| 1 | //===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | //===----------------------------------------------------------------------===// |
| 7 | // |
| 8 | // This file implements a semantic tree transformation that takes a given |
| 9 | // AST and rebuilds it, possibly transforming some nodes in the process. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| 14 | #define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| 15 | |
| 16 | #include "CoroutineStmtBuilder.h" |
| 17 | #include "TypeLocBuilder.h" |
| 18 | #include "clang/AST/Decl.h" |
| 19 | #include "clang/AST/DeclObjC.h" |
| 20 | #include "clang/AST/DeclTemplate.h" |
| 21 | #include "clang/AST/Expr.h" |
| 22 | #include "clang/AST/ExprConcepts.h" |
| 23 | #include "clang/AST/ExprCXX.h" |
| 24 | #include "clang/AST/ExprObjC.h" |
| 25 | #include "clang/AST/ExprOpenMP.h" |
| 26 | #include "clang/AST/OpenMPClause.h" |
| 27 | #include "clang/AST/Stmt.h" |
| 28 | #include "clang/AST/StmtCXX.h" |
| 29 | #include "clang/AST/StmtObjC.h" |
| 30 | #include "clang/AST/StmtOpenMP.h" |
| 31 | #include "clang/Basic/DiagnosticParse.h" |
| 32 | #include "clang/Basic/OpenMPKinds.h" |
| 33 | #include "clang/Sema/Designator.h" |
| 34 | #include "clang/Sema/Lookup.h" |
| 35 | #include "clang/Sema/Ownership.h" |
| 36 | #include "clang/Sema/ParsedTemplate.h" |
| 37 | #include "clang/Sema/ScopeInfo.h" |
| 38 | #include "clang/Sema/SemaDiagnostic.h" |
| 39 | #include "clang/Sema/SemaInternal.h" |
| 40 | #include "llvm/ADT/ArrayRef.h" |
| 41 | #include "llvm/Support/ErrorHandling.h" |
| 42 | #include <algorithm> |
| 43 | |
| 44 | using namespace llvm::omp; |
| 45 | |
| 46 | namespace clang { |
| 47 | using namespace sema; |
| 48 | |
| 49 | /// A semantic tree transformation that allows one to transform one |
| 50 | /// abstract syntax tree into another. |
| 51 | /// |
| 52 | /// A new tree transformation is defined by creating a new subclass \c X of |
| 53 | /// \c TreeTransform<X> and then overriding certain operations to provide |
| 54 | /// behavior specific to that transformation. For example, template |
| 55 | /// instantiation is implemented as a tree transformation where the |
| 56 | /// transformation of TemplateTypeParmType nodes involves substituting the |
| 57 | /// template arguments for their corresponding template parameters; a similar |
| 58 | /// transformation is performed for non-type template parameters and |
| 59 | /// template template parameters. |
| 60 | /// |
| 61 | /// This tree-transformation template uses static polymorphism to allow |
| 62 | /// subclasses to customize any of its operations. Thus, a subclass can |
| 63 | /// override any of the transformation or rebuild operators by providing an |
| 64 | /// operation with the same signature as the default implementation. The |
| 65 | /// overriding function should not be virtual. |
| 66 | /// |
| 67 | /// Semantic tree transformations are split into two stages, either of which |
| 68 | /// can be replaced by a subclass. The "transform" step transforms an AST node |
| 69 | /// or the parts of an AST node using the various transformation functions, |
| 70 | /// then passes the pieces on to the "rebuild" step, which constructs a new AST |
| 71 | /// node of the appropriate kind from the pieces. The default transformation |
| 72 | /// routines recursively transform the operands to composite AST nodes (e.g., |
| 73 | /// the pointee type of a PointerType node) and, if any of those operand nodes |
| 74 | /// were changed by the transformation, invokes the rebuild operation to create |
| 75 | /// a new AST node. |
| 76 | /// |
| 77 | /// Subclasses can customize the transformation at various levels. The |
| 78 | /// most coarse-grained transformations involve replacing TransformType(), |
| 79 | /// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), |
| 80 | /// TransformTemplateName(), or TransformTemplateArgument() with entirely |
| 81 | /// new implementations. |
| 82 | /// |
| 83 | /// For more fine-grained transformations, subclasses can replace any of the |
| 84 | /// \c TransformXXX functions (where XXX is the name of an AST node, e.g., |
| 85 | /// PointerType, StmtExpr) to alter the transformation. As mentioned previously, |
| 86 | /// replacing TransformTemplateTypeParmType() allows template instantiation |
| 87 | /// to substitute template arguments for their corresponding template |
| 88 | /// parameters. Additionally, subclasses can override the \c RebuildXXX |
| 89 | /// functions to control how AST nodes are rebuilt when their operands change. |
| 90 | /// By default, \c TreeTransform will invoke semantic analysis to rebuild |
| 91 | /// AST nodes. However, certain other tree transformations (e.g, cloning) may |
| 92 | /// be able to use more efficient rebuild steps. |
| 93 | /// |
| 94 | /// There are a handful of other functions that can be overridden, allowing one |
| 95 | /// to avoid traversing nodes that don't need any transformation |
| 96 | /// (\c AlreadyTransformed()), force rebuilding AST nodes even when their |
| 97 | /// operands have not changed (\c AlwaysRebuild()), and customize the |
| 98 | /// default locations and entity names used for type-checking |
| 99 | /// (\c getBaseLocation(), \c getBaseEntity()). |
| 100 | template<typename Derived> |
| 101 | class TreeTransform { |
| 102 | /// Private RAII object that helps us forget and then re-remember |
| 103 | /// the template argument corresponding to a partially-substituted parameter |
| 104 | /// pack. |
| 105 | class ForgetPartiallySubstitutedPackRAII { |
| 106 | Derived &Self; |
| 107 | TemplateArgument Old; |
| 108 | |
| 109 | public: |
| 110 | ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { |
| 111 | Old = Self.ForgetPartiallySubstitutedPack(); |
| 112 | } |
| 113 | |
| 114 | ~ForgetPartiallySubstitutedPackRAII() { |
| 115 | Self.RememberPartiallySubstitutedPack(Old); |
| 116 | } |
| 117 | }; |
| 118 | |
| 119 | protected: |
| 120 | Sema &SemaRef; |
| 121 | |
| 122 | /// The set of local declarations that have been transformed, for |
| 123 | /// cases where we are forced to build new declarations within the transformer |
| 124 | /// rather than in the subclass (e.g., lambda closure types). |
| 125 | llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; |
| 126 | |
| 127 | public: |
| 128 | /// Initializes a new tree transformer. |
| 129 | TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } |
| 130 | |
| 131 | /// Retrieves a reference to the derived class. |
| 132 | Derived &getDerived() { return static_cast<Derived&>(*this); } |
| 133 | |
| 134 | /// Retrieves a reference to the derived class. |
| 135 | const Derived &getDerived() const { |
| 136 | return static_cast<const Derived&>(*this); |
| 137 | } |
| 138 | |
| 139 | static inline ExprResult Owned(Expr *E) { return E; } |
| 140 | static inline StmtResult Owned(Stmt *S) { return S; } |
| 141 | |
| 142 | /// Retrieves a reference to the semantic analysis object used for |
| 143 | /// this tree transform. |
| 144 | Sema &getSema() const { return SemaRef; } |
| 145 | |
| 146 | /// Whether the transformation should always rebuild AST nodes, even |
| 147 | /// if none of the children have changed. |
| 148 | /// |
| 149 | /// Subclasses may override this function to specify when the transformation |
| 150 | /// should rebuild all AST nodes. |
| 151 | /// |
| 152 | /// We must always rebuild all AST nodes when performing variadic template |
| 153 | /// pack expansion, in order to avoid violating the AST invariant that each |
| 154 | /// statement node appears at most once in its containing declaration. |
| 155 | bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; } |
| 156 | |
| 157 | /// Whether the transformation is forming an expression or statement that |
| 158 | /// replaces the original. In this case, we'll reuse mangling numbers from |
| 159 | /// existing lambdas. |
| 160 | bool ReplacingOriginal() { return false; } |
| 161 | |
| 162 | /// Wether CXXConstructExpr can be skipped when they are implicit. |
| 163 | /// They will be reconstructed when used if needed. |
| 164 | /// This is usefull when the user that cause rebuilding of the |
| 165 | /// CXXConstructExpr is outside of the expression at which the TreeTransform |
| 166 | /// started. |
| 167 | bool AllowSkippingCXXConstructExpr() { return true; } |
| 168 | |
| 169 | /// Returns the location of the entity being transformed, if that |
| 170 | /// information was not available elsewhere in the AST. |
| 171 | /// |
| 172 | /// By default, returns no source-location information. Subclasses can |
| 173 | /// provide an alternative implementation that provides better location |
| 174 | /// information. |
| 175 | SourceLocation getBaseLocation() { return SourceLocation(); } |
| 176 | |
| 177 | /// Returns the name of the entity being transformed, if that |
| 178 | /// information was not available elsewhere in the AST. |
| 179 | /// |
| 180 | /// By default, returns an empty name. Subclasses can provide an alternative |
| 181 | /// implementation with a more precise name. |
| 182 | DeclarationName getBaseEntity() { return DeclarationName(); } |
| 183 | |
| 184 | /// Sets the "base" location and entity when that |
| 185 | /// information is known based on another transformation. |
| 186 | /// |
| 187 | /// By default, the source location and entity are ignored. Subclasses can |
| 188 | /// override this function to provide a customized implementation. |
| 189 | void setBase(SourceLocation Loc, DeclarationName Entity) { } |
| 190 | |
| 191 | /// RAII object that temporarily sets the base location and entity |
| 192 | /// used for reporting diagnostics in types. |
| 193 | class TemporaryBase { |
| 194 | TreeTransform &Self; |
| 195 | SourceLocation OldLocation; |
| 196 | DeclarationName OldEntity; |
| 197 | |
| 198 | public: |
| 199 | TemporaryBase(TreeTransform &Self, SourceLocation Location, |
| 200 | DeclarationName Entity) : Self(Self) { |
| 201 | OldLocation = Self.getDerived().getBaseLocation(); |
| 202 | OldEntity = Self.getDerived().getBaseEntity(); |
| 203 | |
| 204 | if (Location.isValid()) |
| 205 | Self.getDerived().setBase(Location, Entity); |
| 206 | } |
| 207 | |
| 208 | ~TemporaryBase() { |
| 209 | Self.getDerived().setBase(OldLocation, OldEntity); |
| 210 | } |
| 211 | }; |
| 212 | |
| 213 | /// Determine whether the given type \p T has already been |
| 214 | /// transformed. |
| 215 | /// |
| 216 | /// Subclasses can provide an alternative implementation of this routine |
| 217 | /// to short-circuit evaluation when it is known that a given type will |
| 218 | /// not change. For example, template instantiation need not traverse |
| 219 | /// non-dependent types. |
| 220 | bool AlreadyTransformed(QualType T) { |
| 221 | return T.isNull(); |
| 222 | } |
| 223 | |
| 224 | /// Transform a template parameter depth level. |
| 225 | /// |
| 226 | /// During a transformation that transforms template parameters, this maps |
| 227 | /// an old template parameter depth to a new depth. |
| 228 | unsigned TransformTemplateDepth(unsigned Depth) { |
| 229 | return Depth; |
| 230 | } |
| 231 | |
| 232 | /// Determine whether the given call argument should be dropped, e.g., |
| 233 | /// because it is a default argument. |
| 234 | /// |
| 235 | /// Subclasses can provide an alternative implementation of this routine to |
| 236 | /// determine which kinds of call arguments get dropped. By default, |
| 237 | /// CXXDefaultArgument nodes are dropped (prior to transformation). |
| 238 | bool DropCallArgument(Expr *E) { |
| 239 | return E->isDefaultArgument(); |
| 240 | } |
| 241 | |
| 242 | /// Determine whether we should expand a pack expansion with the |
| 243 | /// given set of parameter packs into separate arguments by repeatedly |
| 244 | /// transforming the pattern. |
| 245 | /// |
| 246 | /// By default, the transformer never tries to expand pack expansions. |
| 247 | /// Subclasses can override this routine to provide different behavior. |
| 248 | /// |
| 249 | /// \param EllipsisLoc The location of the ellipsis that identifies the |
| 250 | /// pack expansion. |
| 251 | /// |
| 252 | /// \param PatternRange The source range that covers the entire pattern of |
| 253 | /// the pack expansion. |
| 254 | /// |
| 255 | /// \param Unexpanded The set of unexpanded parameter packs within the |
| 256 | /// pattern. |
| 257 | /// |
| 258 | /// \param ShouldExpand Will be set to \c true if the transformer should |
| 259 | /// expand the corresponding pack expansions into separate arguments. When |
| 260 | /// set, \c NumExpansions must also be set. |
| 261 | /// |
| 262 | /// \param RetainExpansion Whether the caller should add an unexpanded |
| 263 | /// pack expansion after all of the expanded arguments. This is used |
| 264 | /// when extending explicitly-specified template argument packs per |
| 265 | /// C++0x [temp.arg.explicit]p9. |
| 266 | /// |
| 267 | /// \param NumExpansions The number of separate arguments that will be in |
| 268 | /// the expanded form of the corresponding pack expansion. This is both an |
| 269 | /// input and an output parameter, which can be set by the caller if the |
| 270 | /// number of expansions is known a priori (e.g., due to a prior substitution) |
| 271 | /// and will be set by the callee when the number of expansions is known. |
| 272 | /// The callee must set this value when \c ShouldExpand is \c true; it may |
| 273 | /// set this value in other cases. |
| 274 | /// |
| 275 | /// \returns true if an error occurred (e.g., because the parameter packs |
| 276 | /// are to be instantiated with arguments of different lengths), false |
| 277 | /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) |
| 278 | /// must be set. |
| 279 | bool TryExpandParameterPacks(SourceLocation EllipsisLoc, |
| 280 | SourceRange PatternRange, |
| 281 | ArrayRef<UnexpandedParameterPack> Unexpanded, |
| 282 | bool &ShouldExpand, |
| 283 | bool &RetainExpansion, |
| 284 | Optional<unsigned> &NumExpansions) { |
| 285 | ShouldExpand = false; |
| 286 | return false; |
| 287 | } |
| 288 | |
| 289 | /// "Forget" about the partially-substituted pack template argument, |
| 290 | /// when performing an instantiation that must preserve the parameter pack |
| 291 | /// use. |
| 292 | /// |
| 293 | /// This routine is meant to be overridden by the template instantiator. |
| 294 | TemplateArgument ForgetPartiallySubstitutedPack() { |
| 295 | return TemplateArgument(); |
| 296 | } |
| 297 | |
| 298 | /// "Remember" the partially-substituted pack template argument |
| 299 | /// after performing an instantiation that must preserve the parameter pack |
| 300 | /// use. |
| 301 | /// |
| 302 | /// This routine is meant to be overridden by the template instantiator. |
| 303 | void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } |
| 304 | |
| 305 | /// Note to the derived class when a function parameter pack is |
| 306 | /// being expanded. |
| 307 | void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } |
| 308 | |
| 309 | /// Transforms the given type into another type. |
| 310 | /// |
| 311 | /// By default, this routine transforms a type by creating a |
| 312 | /// TypeSourceInfo for it and delegating to the appropriate |
| 313 | /// function. This is expensive, but we don't mind, because |
| 314 | /// this method is deprecated anyway; all users should be |
| 315 | /// switched to storing TypeSourceInfos. |
| 316 | /// |
| 317 | /// \returns the transformed type. |
| 318 | QualType TransformType(QualType T); |
| 319 | |
| 320 | /// Transforms the given type-with-location into a new |
| 321 | /// type-with-location. |
| 322 | /// |
| 323 | /// By default, this routine transforms a type by delegating to the |
| 324 | /// appropriate TransformXXXType to build a new type. Subclasses |
| 325 | /// may override this function (to take over all type |
| 326 | /// transformations) or some set of the TransformXXXType functions |
| 327 | /// to alter the transformation. |
| 328 | TypeSourceInfo *TransformType(TypeSourceInfo *DI); |
| 329 | |
| 330 | /// Transform the given type-with-location into a new |
| 331 | /// type, collecting location information in the given builder |
| 332 | /// as necessary. |
| 333 | /// |
| 334 | QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); |
| 335 | |
| 336 | /// Transform a type that is permitted to produce a |
| 337 | /// DeducedTemplateSpecializationType. |
| 338 | /// |
| 339 | /// This is used in the (relatively rare) contexts where it is acceptable |
| 340 | /// for transformation to produce a class template type with deduced |
| 341 | /// template arguments. |
| 342 | /// @{ |
| 343 | QualType TransformTypeWithDeducedTST(QualType T); |
| 344 | TypeSourceInfo *TransformTypeWithDeducedTST(TypeSourceInfo *DI); |
| 345 | /// @} |
| 346 | |
| 347 | /// The reason why the value of a statement is not discarded, if any. |
| 348 | enum StmtDiscardKind { |
| 349 | SDK_Discarded, |
| 350 | SDK_NotDiscarded, |
| 351 | SDK_StmtExprResult, |
| 352 | }; |
| 353 | |
| 354 | /// Transform the given statement. |
| 355 | /// |
| 356 | /// By default, this routine transforms a statement by delegating to the |
| 357 | /// appropriate TransformXXXStmt function to transform a specific kind of |
| 358 | /// statement or the TransformExpr() function to transform an expression. |
| 359 | /// Subclasses may override this function to transform statements using some |
| 360 | /// other mechanism. |
| 361 | /// |
| 362 | /// \returns the transformed statement. |
| 363 | StmtResult TransformStmt(Stmt *S, StmtDiscardKind SDK = SDK_Discarded); |
| 364 | |
| 365 | /// Transform the given statement. |
| 366 | /// |
| 367 | /// By default, this routine transforms a statement by delegating to the |
| 368 | /// appropriate TransformOMPXXXClause function to transform a specific kind |
| 369 | /// of clause. Subclasses may override this function to transform statements |
| 370 | /// using some other mechanism. |
| 371 | /// |
| 372 | /// \returns the transformed OpenMP clause. |
| 373 | OMPClause *TransformOMPClause(OMPClause *S); |
| 374 | |
| 375 | /// Transform the given attribute. |
| 376 | /// |
| 377 | /// By default, this routine transforms a statement by delegating to the |
| 378 | /// appropriate TransformXXXAttr function to transform a specific kind |
| 379 | /// of attribute. Subclasses may override this function to transform |
| 380 | /// attributed statements using some other mechanism. |
| 381 | /// |
| 382 | /// \returns the transformed attribute |
| 383 | const Attr *TransformAttr(const Attr *S); |
| 384 | |
| 385 | /// Transform the specified attribute. |
| 386 | /// |
| 387 | /// Subclasses should override the transformation of attributes with a pragma |
| 388 | /// spelling to transform expressions stored within the attribute. |
| 389 | /// |
| 390 | /// \returns the transformed attribute. |
| 391 | #define ATTR(X) |
| 392 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 393 | const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; } |
| 394 | #include "clang/Basic/AttrList.inc" |
| 395 | |
| 396 | /// Transform the given expression. |
| 397 | /// |
| 398 | /// By default, this routine transforms an expression by delegating to the |
| 399 | /// appropriate TransformXXXExpr function to build a new expression. |
| 400 | /// Subclasses may override this function to transform expressions using some |
| 401 | /// other mechanism. |
| 402 | /// |
| 403 | /// \returns the transformed expression. |
| 404 | ExprResult TransformExpr(Expr *E); |
| 405 | |
| 406 | /// Transform the given initializer. |
| 407 | /// |
| 408 | /// By default, this routine transforms an initializer by stripping off the |
| 409 | /// semantic nodes added by initialization, then passing the result to |
| 410 | /// TransformExpr or TransformExprs. |
| 411 | /// |
| 412 | /// \returns the transformed initializer. |
| 413 | ExprResult TransformInitializer(Expr *Init, bool NotCopyInit); |
| 414 | |
| 415 | /// Transform the given list of expressions. |
| 416 | /// |
| 417 | /// This routine transforms a list of expressions by invoking |
| 418 | /// \c TransformExpr() for each subexpression. However, it also provides |
| 419 | /// support for variadic templates by expanding any pack expansions (if the |
| 420 | /// derived class permits such expansion) along the way. When pack expansions |
| 421 | /// are present, the number of outputs may not equal the number of inputs. |
| 422 | /// |
| 423 | /// \param Inputs The set of expressions to be transformed. |
| 424 | /// |
| 425 | /// \param NumInputs The number of expressions in \c Inputs. |
| 426 | /// |
| 427 | /// \param IsCall If \c true, then this transform is being performed on |
| 428 | /// function-call arguments, and any arguments that should be dropped, will |
| 429 | /// be. |
| 430 | /// |
| 431 | /// \param Outputs The transformed input expressions will be added to this |
| 432 | /// vector. |
| 433 | /// |
| 434 | /// \param ArgChanged If non-NULL, will be set \c true if any argument changed |
| 435 | /// due to transformation. |
| 436 | /// |
| 437 | /// \returns true if an error occurred, false otherwise. |
| 438 | bool TransformExprs(Expr *const *Inputs, unsigned NumInputs, bool IsCall, |
| 439 | SmallVectorImpl<Expr *> &Outputs, |
| 440 | bool *ArgChanged = nullptr); |
| 441 | |
| 442 | /// Transform the given declaration, which is referenced from a type |
| 443 | /// or expression. |
| 444 | /// |
| 445 | /// By default, acts as the identity function on declarations, unless the |
| 446 | /// transformer has had to transform the declaration itself. Subclasses |
| 447 | /// may override this function to provide alternate behavior. |
| 448 | Decl *TransformDecl(SourceLocation Loc, Decl *D) { |
| 449 | llvm::DenseMap<Decl *, Decl *>::iterator Known |
| 450 | = TransformedLocalDecls.find(D); |
| 451 | if (Known != TransformedLocalDecls.end()) |
| 452 | return Known->second; |
| 453 | |
| 454 | return D; |
| 455 | } |
| 456 | |
| 457 | /// Transform the specified condition. |
| 458 | /// |
| 459 | /// By default, this transforms the variable and expression and rebuilds |
| 460 | /// the condition. |
| 461 | Sema::ConditionResult TransformCondition(SourceLocation Loc, VarDecl *Var, |
| 462 | Expr *Expr, |
| 463 | Sema::ConditionKind Kind); |
| 464 | |
| 465 | /// Transform the attributes associated with the given declaration and |
| 466 | /// place them on the new declaration. |
| 467 | /// |
| 468 | /// By default, this operation does nothing. Subclasses may override this |
| 469 | /// behavior to transform attributes. |
| 470 | void transformAttrs(Decl *Old, Decl *New) { } |
| 471 | |
| 472 | /// Note that a local declaration has been transformed by this |
| 473 | /// transformer. |
| 474 | /// |
| 475 | /// Local declarations are typically transformed via a call to |
| 476 | /// TransformDefinition. However, in some cases (e.g., lambda expressions), |
| 477 | /// the transformer itself has to transform the declarations. This routine |
| 478 | /// can be overridden by a subclass that keeps track of such mappings. |
| 479 | void transformedLocalDecl(Decl *Old, ArrayRef<Decl *> New) { |
| 480 | assert(New.size() == 1 && |
| 481 | "must override transformedLocalDecl if performing pack expansion" ); |
| 482 | TransformedLocalDecls[Old] = New.front(); |
| 483 | } |
| 484 | |
| 485 | /// Transform the definition of the given declaration. |
| 486 | /// |
| 487 | /// By default, invokes TransformDecl() to transform the declaration. |
| 488 | /// Subclasses may override this function to provide alternate behavior. |
| 489 | Decl *TransformDefinition(SourceLocation Loc, Decl *D) { |
| 490 | return getDerived().TransformDecl(Loc, D); |
| 491 | } |
| 492 | |
| 493 | /// Transform the given declaration, which was the first part of a |
| 494 | /// nested-name-specifier in a member access expression. |
| 495 | /// |
| 496 | /// This specific declaration transformation only applies to the first |
| 497 | /// identifier in a nested-name-specifier of a member access expression, e.g., |
| 498 | /// the \c T in \c x->T::member |
| 499 | /// |
| 500 | /// By default, invokes TransformDecl() to transform the declaration. |
| 501 | /// Subclasses may override this function to provide alternate behavior. |
| 502 | NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { |
| 503 | return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); |
| 504 | } |
| 505 | |
| 506 | /// Transform the set of declarations in an OverloadExpr. |
| 507 | bool TransformOverloadExprDecls(OverloadExpr *Old, bool RequiresADL, |
| 508 | LookupResult &R); |
| 509 | |
| 510 | /// Transform the given nested-name-specifier with source-location |
| 511 | /// information. |
| 512 | /// |
| 513 | /// By default, transforms all of the types and declarations within the |
| 514 | /// nested-name-specifier. Subclasses may override this function to provide |
| 515 | /// alternate behavior. |
| 516 | NestedNameSpecifierLoc |
| 517 | TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS, |
| 518 | QualType ObjectType = QualType(), |
| 519 | NamedDecl *FirstQualifierInScope = nullptr); |
| 520 | |
| 521 | /// Transform the given declaration name. |
| 522 | /// |
| 523 | /// By default, transforms the types of conversion function, constructor, |
| 524 | /// and destructor names and then (if needed) rebuilds the declaration name. |
| 525 | /// Identifiers and selectors are returned unmodified. Sublcasses may |
| 526 | /// override this function to provide alternate behavior. |
| 527 | DeclarationNameInfo |
| 528 | TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); |
| 529 | |
| 530 | bool TransformRequiresExprRequirements(ArrayRef<concepts::Requirement *> Reqs, |
| 531 | llvm::SmallVectorImpl<concepts::Requirement *> &Transformed); |
| 532 | concepts::TypeRequirement * |
| 533 | TransformTypeRequirement(concepts::TypeRequirement *Req); |
| 534 | concepts::ExprRequirement * |
| 535 | TransformExprRequirement(concepts::ExprRequirement *Req); |
| 536 | concepts::NestedRequirement * |
| 537 | TransformNestedRequirement(concepts::NestedRequirement *Req); |
| 538 | |
| 539 | /// Transform the given template name. |
| 540 | /// |
| 541 | /// \param SS The nested-name-specifier that qualifies the template |
| 542 | /// name. This nested-name-specifier must already have been transformed. |
| 543 | /// |
| 544 | /// \param Name The template name to transform. |
| 545 | /// |
| 546 | /// \param NameLoc The source location of the template name. |
| 547 | /// |
| 548 | /// \param ObjectType If we're translating a template name within a member |
| 549 | /// access expression, this is the type of the object whose member template |
| 550 | /// is being referenced. |
| 551 | /// |
| 552 | /// \param FirstQualifierInScope If the first part of a nested-name-specifier |
| 553 | /// also refers to a name within the current (lexical) scope, this is the |
| 554 | /// declaration it refers to. |
| 555 | /// |
| 556 | /// By default, transforms the template name by transforming the declarations |
| 557 | /// and nested-name-specifiers that occur within the template name. |
| 558 | /// Subclasses may override this function to provide alternate behavior. |
| 559 | TemplateName |
| 560 | TransformTemplateName(CXXScopeSpec &SS, TemplateName Name, |
| 561 | SourceLocation NameLoc, |
| 562 | QualType ObjectType = QualType(), |
| 563 | NamedDecl *FirstQualifierInScope = nullptr, |
| 564 | bool AllowInjectedClassName = false); |
| 565 | |
| 566 | /// Transform the given template argument. |
| 567 | /// |
| 568 | /// By default, this operation transforms the type, expression, or |
| 569 | /// declaration stored within the template argument and constructs a |
| 570 | /// new template argument from the transformed result. Subclasses may |
| 571 | /// override this function to provide alternate behavior. |
| 572 | /// |
| 573 | /// Returns true if there was an error. |
| 574 | bool TransformTemplateArgument(const TemplateArgumentLoc &Input, |
| 575 | TemplateArgumentLoc &Output, |
| 576 | bool Uneval = false); |
| 577 | |
| 578 | /// Transform the given set of template arguments. |
| 579 | /// |
| 580 | /// By default, this operation transforms all of the template arguments |
| 581 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 582 | /// the transformed arguments to the output list. |
| 583 | /// |
| 584 | /// Note that this overload of \c TransformTemplateArguments() is merely |
| 585 | /// a convenience function. Subclasses that wish to override this behavior |
| 586 | /// should override the iterator-based member template version. |
| 587 | /// |
| 588 | /// \param Inputs The set of template arguments to be transformed. |
| 589 | /// |
| 590 | /// \param NumInputs The number of template arguments in \p Inputs. |
| 591 | /// |
| 592 | /// \param Outputs The set of transformed template arguments output by this |
| 593 | /// routine. |
| 594 | /// |
| 595 | /// Returns true if an error occurred. |
| 596 | bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, |
| 597 | unsigned NumInputs, |
| 598 | TemplateArgumentListInfo &Outputs, |
| 599 | bool Uneval = false) { |
| 600 | return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs, |
| 601 | Uneval); |
| 602 | } |
| 603 | |
| 604 | /// Transform the given set of template arguments. |
| 605 | /// |
| 606 | /// By default, this operation transforms all of the template arguments |
| 607 | /// in the input set using \c TransformTemplateArgument(), and appends |
| 608 | /// the transformed arguments to the output list. |
| 609 | /// |
| 610 | /// \param First An iterator to the first template argument. |
| 611 | /// |
| 612 | /// \param Last An iterator one step past the last template argument. |
| 613 | /// |
| 614 | /// \param Outputs The set of transformed template arguments output by this |
| 615 | /// routine. |
| 616 | /// |
| 617 | /// Returns true if an error occurred. |
| 618 | template<typename InputIterator> |
| 619 | bool TransformTemplateArguments(InputIterator First, |
| 620 | InputIterator Last, |
| 621 | TemplateArgumentListInfo &Outputs, |
| 622 | bool Uneval = false); |
| 623 | |
| 624 | /// Fakes up a TemplateArgumentLoc for a given TemplateArgument. |
| 625 | void InventTemplateArgumentLoc(const TemplateArgument &Arg, |
| 626 | TemplateArgumentLoc &ArgLoc); |
| 627 | |
| 628 | /// Fakes up a TypeSourceInfo for a type. |
| 629 | TypeSourceInfo *InventTypeSourceInfo(QualType T) { |
| 630 | return SemaRef.Context.getTrivialTypeSourceInfo(T, |
| 631 | getDerived().getBaseLocation()); |
| 632 | } |
| 633 | |
| 634 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 635 | #define TYPELOC(CLASS, PARENT) \ |
| 636 | QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); |
| 637 | #include "clang/AST/TypeLocNodes.def" |
| 638 | |
| 639 | template<typename Fn> |
| 640 | QualType TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 641 | FunctionProtoTypeLoc TL, |
| 642 | CXXRecordDecl *ThisContext, |
| 643 | Qualifiers ThisTypeQuals, |
| 644 | Fn TransformExceptionSpec); |
| 645 | |
| 646 | bool TransformExceptionSpec(SourceLocation Loc, |
| 647 | FunctionProtoType::ExceptionSpecInfo &ESI, |
| 648 | SmallVectorImpl<QualType> &Exceptions, |
| 649 | bool &Changed); |
| 650 | |
| 651 | StmtResult TransformSEHHandler(Stmt *Handler); |
| 652 | |
| 653 | QualType |
| 654 | TransformTemplateSpecializationType(TypeLocBuilder &TLB, |
| 655 | TemplateSpecializationTypeLoc TL, |
| 656 | TemplateName Template); |
| 657 | |
| 658 | QualType |
| 659 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 660 | DependentTemplateSpecializationTypeLoc TL, |
| 661 | TemplateName Template, |
| 662 | CXXScopeSpec &SS); |
| 663 | |
| 664 | QualType TransformDependentTemplateSpecializationType( |
| 665 | TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL, |
| 666 | NestedNameSpecifierLoc QualifierLoc); |
| 667 | |
| 668 | /// Transforms the parameters of a function type into the |
| 669 | /// given vectors. |
| 670 | /// |
| 671 | /// The result vectors should be kept in sync; null entries in the |
| 672 | /// variables vector are acceptable. |
| 673 | /// |
| 674 | /// Return true on error. |
| 675 | bool TransformFunctionTypeParams( |
| 676 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 677 | const QualType *ParamTypes, |
| 678 | const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 679 | SmallVectorImpl<QualType> &PTypes, SmallVectorImpl<ParmVarDecl *> *PVars, |
| 680 | Sema::ExtParameterInfoBuilder &PInfos); |
| 681 | |
| 682 | /// Transforms a single function-type parameter. Return null |
| 683 | /// on error. |
| 684 | /// |
| 685 | /// \param indexAdjustment - A number to add to the parameter's |
| 686 | /// scope index; can be negative |
| 687 | ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, |
| 688 | int indexAdjustment, |
| 689 | Optional<unsigned> NumExpansions, |
| 690 | bool ExpectParameterPack); |
| 691 | |
| 692 | /// Transform the body of a lambda-expression. |
| 693 | StmtResult TransformLambdaBody(LambdaExpr *E, Stmt *Body); |
| 694 | /// Alternative implementation of TransformLambdaBody that skips transforming |
| 695 | /// the body. |
| 696 | StmtResult SkipLambdaBody(LambdaExpr *E, Stmt *Body); |
| 697 | |
| 698 | QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); |
| 699 | |
| 700 | StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); |
| 701 | ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); |
| 702 | |
| 703 | TemplateParameterList *TransformTemplateParameterList( |
| 704 | TemplateParameterList *TPL) { |
| 705 | return TPL; |
| 706 | } |
| 707 | |
| 708 | ExprResult TransformAddressOfOperand(Expr *E); |
| 709 | |
| 710 | ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E, |
| 711 | bool IsAddressOfOperand, |
| 712 | TypeSourceInfo **RecoveryTSI); |
| 713 | |
| 714 | ExprResult TransformParenDependentScopeDeclRefExpr( |
| 715 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand, |
| 716 | TypeSourceInfo **RecoveryTSI); |
| 717 | |
| 718 | StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S); |
| 719 | |
| 720 | // FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous |
| 721 | // amount of stack usage with clang. |
| 722 | #define STMT(Node, Parent) \ |
| 723 | LLVM_ATTRIBUTE_NOINLINE \ |
| 724 | StmtResult Transform##Node(Node *S); |
| 725 | #define VALUESTMT(Node, Parent) \ |
| 726 | LLVM_ATTRIBUTE_NOINLINE \ |
| 727 | StmtResult Transform##Node(Node *S, StmtDiscardKind SDK); |
| 728 | #define EXPR(Node, Parent) \ |
| 729 | LLVM_ATTRIBUTE_NOINLINE \ |
| 730 | ExprResult Transform##Node(Node *E); |
| 731 | #define ABSTRACT_STMT(Stmt) |
| 732 | #include "clang/AST/StmtNodes.inc" |
| 733 | |
| 734 | #define GEN_CLANG_CLAUSE_CLASS |
| 735 | #define CLAUSE_CLASS(Enum, Str, Class) \ |
| 736 | LLVM_ATTRIBUTE_NOINLINE \ |
| 737 | OMPClause *Transform##Class(Class *S); |
| 738 | #include "llvm/Frontend/OpenMP/OMP.inc" |
| 739 | |
| 740 | /// Build a new qualified type given its unqualified type and type location. |
| 741 | /// |
| 742 | /// By default, this routine adds type qualifiers only to types that can |
| 743 | /// have qualifiers, and silently suppresses those qualifiers that are not |
| 744 | /// permitted. Subclasses may override this routine to provide different |
| 745 | /// behavior. |
| 746 | QualType RebuildQualifiedType(QualType T, QualifiedTypeLoc TL); |
| 747 | |
| 748 | /// Build a new pointer type given its pointee type. |
| 749 | /// |
| 750 | /// By default, performs semantic analysis when building the pointer type. |
| 751 | /// Subclasses may override this routine to provide different behavior. |
| 752 | QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); |
| 753 | |
| 754 | /// Build a new block pointer type given its pointee type. |
| 755 | /// |
| 756 | /// By default, performs semantic analysis when building the block pointer |
| 757 | /// type. Subclasses may override this routine to provide different behavior. |
| 758 | QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); |
| 759 | |
| 760 | /// Build a new reference type given the type it references. |
| 761 | /// |
| 762 | /// By default, performs semantic analysis when building the |
| 763 | /// reference type. Subclasses may override this routine to provide |
| 764 | /// different behavior. |
| 765 | /// |
| 766 | /// \param LValue whether the type was written with an lvalue sigil |
| 767 | /// or an rvalue sigil. |
| 768 | QualType RebuildReferenceType(QualType ReferentType, |
| 769 | bool LValue, |
| 770 | SourceLocation Sigil); |
| 771 | |
| 772 | /// Build a new member pointer type given the pointee type and the |
| 773 | /// class type it refers into. |
| 774 | /// |
| 775 | /// By default, performs semantic analysis when building the member pointer |
| 776 | /// type. Subclasses may override this routine to provide different behavior. |
| 777 | QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, |
| 778 | SourceLocation Sigil); |
| 779 | |
| 780 | QualType RebuildObjCTypeParamType(const ObjCTypeParamDecl *Decl, |
| 781 | SourceLocation ProtocolLAngleLoc, |
| 782 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 783 | ArrayRef<SourceLocation> ProtocolLocs, |
| 784 | SourceLocation ProtocolRAngleLoc); |
| 785 | |
| 786 | /// Build an Objective-C object type. |
| 787 | /// |
| 788 | /// By default, performs semantic analysis when building the object type. |
| 789 | /// Subclasses may override this routine to provide different behavior. |
| 790 | QualType RebuildObjCObjectType(QualType BaseType, |
| 791 | SourceLocation Loc, |
| 792 | SourceLocation TypeArgsLAngleLoc, |
| 793 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 794 | SourceLocation TypeArgsRAngleLoc, |
| 795 | SourceLocation ProtocolLAngleLoc, |
| 796 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 797 | ArrayRef<SourceLocation> ProtocolLocs, |
| 798 | SourceLocation ProtocolRAngleLoc); |
| 799 | |
| 800 | /// Build a new Objective-C object pointer type given the pointee type. |
| 801 | /// |
| 802 | /// By default, directly builds the pointer type, with no additional semantic |
| 803 | /// analysis. |
| 804 | QualType RebuildObjCObjectPointerType(QualType PointeeType, |
| 805 | SourceLocation Star); |
| 806 | |
| 807 | /// Build a new array type given the element type, size |
| 808 | /// modifier, size of the array (if known), size expression, and index type |
| 809 | /// qualifiers. |
| 810 | /// |
| 811 | /// By default, performs semantic analysis when building the array type. |
| 812 | /// Subclasses may override this routine to provide different behavior. |
| 813 | /// Also by default, all of the other Rebuild*Array |
| 814 | QualType RebuildArrayType(QualType ElementType, |
| 815 | ArrayType::ArraySizeModifier SizeMod, |
| 816 | const llvm::APInt *Size, |
| 817 | Expr *SizeExpr, |
| 818 | unsigned IndexTypeQuals, |
| 819 | SourceRange BracketsRange); |
| 820 | |
| 821 | /// Build a new constant array type given the element type, size |
| 822 | /// modifier, (known) size of the array, and index type qualifiers. |
| 823 | /// |
| 824 | /// By default, performs semantic analysis when building the array type. |
| 825 | /// Subclasses may override this routine to provide different behavior. |
| 826 | QualType RebuildConstantArrayType(QualType ElementType, |
| 827 | ArrayType::ArraySizeModifier SizeMod, |
| 828 | const llvm::APInt &Size, |
| 829 | Expr *SizeExpr, |
| 830 | unsigned IndexTypeQuals, |
| 831 | SourceRange BracketsRange); |
| 832 | |
| 833 | /// Build a new incomplete array type given the element type, size |
| 834 | /// modifier, and index type qualifiers. |
| 835 | /// |
| 836 | /// By default, performs semantic analysis when building the array type. |
| 837 | /// Subclasses may override this routine to provide different behavior. |
| 838 | QualType RebuildIncompleteArrayType(QualType ElementType, |
| 839 | ArrayType::ArraySizeModifier SizeMod, |
| 840 | unsigned IndexTypeQuals, |
| 841 | SourceRange BracketsRange); |
| 842 | |
| 843 | /// Build a new variable-length array type given the element type, |
| 844 | /// size modifier, size expression, and index type qualifiers. |
| 845 | /// |
| 846 | /// By default, performs semantic analysis when building the array type. |
| 847 | /// Subclasses may override this routine to provide different behavior. |
| 848 | QualType RebuildVariableArrayType(QualType ElementType, |
| 849 | ArrayType::ArraySizeModifier SizeMod, |
| 850 | Expr *SizeExpr, |
| 851 | unsigned IndexTypeQuals, |
| 852 | SourceRange BracketsRange); |
| 853 | |
| 854 | /// Build a new dependent-sized array type given the element type, |
| 855 | /// size modifier, size expression, and index type qualifiers. |
| 856 | /// |
| 857 | /// By default, performs semantic analysis when building the array type. |
| 858 | /// Subclasses may override this routine to provide different behavior. |
| 859 | QualType RebuildDependentSizedArrayType(QualType ElementType, |
| 860 | ArrayType::ArraySizeModifier SizeMod, |
| 861 | Expr *SizeExpr, |
| 862 | unsigned IndexTypeQuals, |
| 863 | SourceRange BracketsRange); |
| 864 | |
| 865 | /// Build a new vector type given the element type and |
| 866 | /// number of elements. |
| 867 | /// |
| 868 | /// By default, performs semantic analysis when building the vector type. |
| 869 | /// Subclasses may override this routine to provide different behavior. |
| 870 | QualType RebuildVectorType(QualType ElementType, unsigned NumElements, |
| 871 | VectorType::VectorKind VecKind); |
| 872 | |
| 873 | /// Build a new potentially dependently-sized extended vector type |
| 874 | /// given the element type and number of elements. |
| 875 | /// |
| 876 | /// By default, performs semantic analysis when building the vector type. |
| 877 | /// Subclasses may override this routine to provide different behavior. |
| 878 | QualType RebuildDependentVectorType(QualType ElementType, Expr *SizeExpr, |
| 879 | SourceLocation AttributeLoc, |
| 880 | VectorType::VectorKind); |
| 881 | |
| 882 | /// Build a new extended vector type given the element type and |
| 883 | /// number of elements. |
| 884 | /// |
| 885 | /// By default, performs semantic analysis when building the vector type. |
| 886 | /// Subclasses may override this routine to provide different behavior. |
| 887 | QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, |
| 888 | SourceLocation AttributeLoc); |
| 889 | |
| 890 | /// Build a new potentially dependently-sized extended vector type |
| 891 | /// given the element type and number of elements. |
| 892 | /// |
| 893 | /// By default, performs semantic analysis when building the vector type. |
| 894 | /// Subclasses may override this routine to provide different behavior. |
| 895 | QualType RebuildDependentSizedExtVectorType(QualType ElementType, |
| 896 | Expr *SizeExpr, |
| 897 | SourceLocation AttributeLoc); |
| 898 | |
| 899 | /// Build a new matrix type given the element type and dimensions. |
| 900 | QualType RebuildConstantMatrixType(QualType ElementType, unsigned NumRows, |
| 901 | unsigned NumColumns); |
| 902 | |
| 903 | /// Build a new matrix type given the type and dependently-defined |
| 904 | /// dimensions. |
| 905 | QualType RebuildDependentSizedMatrixType(QualType ElementType, Expr *RowExpr, |
| 906 | Expr *ColumnExpr, |
| 907 | SourceLocation AttributeLoc); |
| 908 | |
| 909 | /// Build a new DependentAddressSpaceType or return the pointee |
| 910 | /// type variable with the correct address space (retrieved from |
| 911 | /// AddrSpaceExpr) applied to it. The former will be returned in cases |
| 912 | /// where the address space remains dependent. |
| 913 | /// |
| 914 | /// By default, performs semantic analysis when building the type with address |
| 915 | /// space applied. Subclasses may override this routine to provide different |
| 916 | /// behavior. |
| 917 | QualType RebuildDependentAddressSpaceType(QualType PointeeType, |
| 918 | Expr *AddrSpaceExpr, |
| 919 | SourceLocation AttributeLoc); |
| 920 | |
| 921 | /// Build a new function type. |
| 922 | /// |
| 923 | /// By default, performs semantic analysis when building the function type. |
| 924 | /// Subclasses may override this routine to provide different behavior. |
| 925 | QualType RebuildFunctionProtoType(QualType T, |
| 926 | MutableArrayRef<QualType> ParamTypes, |
| 927 | const FunctionProtoType::ExtProtoInfo &EPI); |
| 928 | |
| 929 | /// Build a new unprototyped function type. |
| 930 | QualType RebuildFunctionNoProtoType(QualType ResultType); |
| 931 | |
| 932 | /// Rebuild an unresolved typename type, given the decl that |
| 933 | /// the UnresolvedUsingTypenameDecl was transformed to. |
| 934 | QualType RebuildUnresolvedUsingType(SourceLocation NameLoc, Decl *D); |
| 935 | |
| 936 | /// Build a new typedef type. |
| 937 | QualType RebuildTypedefType(TypedefNameDecl *Typedef) { |
| 938 | return SemaRef.Context.getTypeDeclType(Typedef); |
| 939 | } |
| 940 | |
| 941 | /// Build a new MacroDefined type. |
| 942 | QualType RebuildMacroQualifiedType(QualType T, |
| 943 | const IdentifierInfo *MacroII) { |
| 944 | return SemaRef.Context.getMacroQualifiedType(T, MacroII); |
| 945 | } |
| 946 | |
| 947 | /// Build a new class/struct/union type. |
| 948 | QualType RebuildRecordType(RecordDecl *Record) { |
| 949 | return SemaRef.Context.getTypeDeclType(Record); |
| 950 | } |
| 951 | |
| 952 | /// Build a new Enum type. |
| 953 | QualType RebuildEnumType(EnumDecl *Enum) { |
| 954 | return SemaRef.Context.getTypeDeclType(Enum); |
| 955 | } |
| 956 | |
| 957 | /// Build a new typeof(expr) type. |
| 958 | /// |
| 959 | /// By default, performs semantic analysis when building the typeof type. |
| 960 | /// Subclasses may override this routine to provide different behavior. |
| 961 | QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); |
| 962 | |
| 963 | /// Build a new typeof(type) type. |
| 964 | /// |
| 965 | /// By default, builds a new TypeOfType with the given underlying type. |
| 966 | QualType RebuildTypeOfType(QualType Underlying); |
| 967 | |
| 968 | /// Build a new unary transform type. |
| 969 | QualType RebuildUnaryTransformType(QualType BaseType, |
| 970 | UnaryTransformType::UTTKind UKind, |
| 971 | SourceLocation Loc); |
| 972 | |
| 973 | /// Build a new C++11 decltype type. |
| 974 | /// |
| 975 | /// By default, performs semantic analysis when building the decltype type. |
| 976 | /// Subclasses may override this routine to provide different behavior. |
| 977 | QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); |
| 978 | |
| 979 | /// Build a new C++11 auto type. |
| 980 | /// |
| 981 | /// By default, builds a new AutoType with the given deduced type. |
| 982 | QualType RebuildAutoType(QualType Deduced, AutoTypeKeyword Keyword, |
| 983 | ConceptDecl *TypeConstraintConcept, |
| 984 | ArrayRef<TemplateArgument> TypeConstraintArgs) { |
| 985 | // Note, IsDependent is always false here: we implicitly convert an 'auto' |
| 986 | // which has been deduced to a dependent type into an undeduced 'auto', so |
| 987 | // that we'll retry deduction after the transformation. |
| 988 | return SemaRef.Context.getAutoType(Deduced, Keyword, |
| 989 | /*IsDependent*/ false, /*IsPack=*/false, |
| 990 | TypeConstraintConcept, |
| 991 | TypeConstraintArgs); |
| 992 | } |
| 993 | |
| 994 | /// By default, builds a new DeducedTemplateSpecializationType with the given |
| 995 | /// deduced type. |
| 996 | QualType RebuildDeducedTemplateSpecializationType(TemplateName Template, |
| 997 | QualType Deduced) { |
| 998 | return SemaRef.Context.getDeducedTemplateSpecializationType( |
| 999 | Template, Deduced, /*IsDependent*/ false); |
| 1000 | } |
| 1001 | |
| 1002 | /// Build a new template specialization type. |
| 1003 | /// |
| 1004 | /// By default, performs semantic analysis when building the template |
| 1005 | /// specialization type. Subclasses may override this routine to provide |
| 1006 | /// different behavior. |
| 1007 | QualType RebuildTemplateSpecializationType(TemplateName Template, |
| 1008 | SourceLocation TemplateLoc, |
| 1009 | TemplateArgumentListInfo &Args); |
| 1010 | |
| 1011 | /// Build a new parenthesized type. |
| 1012 | /// |
| 1013 | /// By default, builds a new ParenType type from the inner type. |
| 1014 | /// Subclasses may override this routine to provide different behavior. |
| 1015 | QualType RebuildParenType(QualType InnerType) { |
| 1016 | return SemaRef.BuildParenType(InnerType); |
| 1017 | } |
| 1018 | |
| 1019 | /// Build a new qualified name type. |
| 1020 | /// |
| 1021 | /// By default, builds a new ElaboratedType type from the keyword, |
| 1022 | /// the nested-name-specifier and the named type. |
| 1023 | /// Subclasses may override this routine to provide different behavior. |
| 1024 | QualType RebuildElaboratedType(SourceLocation KeywordLoc, |
| 1025 | ElaboratedTypeKeyword Keyword, |
| 1026 | NestedNameSpecifierLoc QualifierLoc, |
| 1027 | QualType Named) { |
| 1028 | return SemaRef.Context.getElaboratedType(Keyword, |
| 1029 | QualifierLoc.getNestedNameSpecifier(), |
| 1030 | Named); |
| 1031 | } |
| 1032 | |
| 1033 | /// Build a new typename type that refers to a template-id. |
| 1034 | /// |
| 1035 | /// By default, builds a new DependentNameType type from the |
| 1036 | /// nested-name-specifier and the given type. Subclasses may override |
| 1037 | /// this routine to provide different behavior. |
| 1038 | QualType RebuildDependentTemplateSpecializationType( |
| 1039 | ElaboratedTypeKeyword Keyword, |
| 1040 | NestedNameSpecifierLoc QualifierLoc, |
| 1041 | SourceLocation TemplateKWLoc, |
| 1042 | const IdentifierInfo *Name, |
| 1043 | SourceLocation NameLoc, |
| 1044 | TemplateArgumentListInfo &Args, |
| 1045 | bool AllowInjectedClassName) { |
| 1046 | // Rebuild the template name. |
| 1047 | // TODO: avoid TemplateName abstraction |
| 1048 | CXXScopeSpec SS; |
| 1049 | SS.Adopt(QualifierLoc); |
| 1050 | TemplateName InstName = getDerived().RebuildTemplateName( |
| 1051 | SS, TemplateKWLoc, *Name, NameLoc, QualType(), nullptr, |
| 1052 | AllowInjectedClassName); |
| 1053 | |
| 1054 | if (InstName.isNull()) |
| 1055 | return QualType(); |
| 1056 | |
| 1057 | // If it's still dependent, make a dependent specialization. |
| 1058 | if (InstName.getAsDependentTemplateName()) |
| 1059 | return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, |
| 1060 | QualifierLoc.getNestedNameSpecifier(), |
| 1061 | Name, |
| 1062 | Args); |
| 1063 | |
| 1064 | // Otherwise, make an elaborated type wrapping a non-dependent |
| 1065 | // specialization. |
| 1066 | QualType T = |
| 1067 | getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); |
| 1068 | if (T.isNull()) return QualType(); |
| 1069 | |
| 1070 | if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr) |
| 1071 | return T; |
| 1072 | |
| 1073 | return SemaRef.Context.getElaboratedType(Keyword, |
| 1074 | QualifierLoc.getNestedNameSpecifier(), |
| 1075 | T); |
| 1076 | } |
| 1077 | |
| 1078 | /// Build a new typename type that refers to an identifier. |
| 1079 | /// |
| 1080 | /// By default, performs semantic analysis when building the typename type |
| 1081 | /// (or elaborated type). Subclasses may override this routine to provide |
| 1082 | /// different behavior. |
| 1083 | QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, |
| 1084 | SourceLocation KeywordLoc, |
| 1085 | NestedNameSpecifierLoc QualifierLoc, |
| 1086 | const IdentifierInfo *Id, |
| 1087 | SourceLocation IdLoc, |
| 1088 | bool DeducedTSTContext) { |
| 1089 | CXXScopeSpec SS; |
| 1090 | SS.Adopt(QualifierLoc); |
| 1091 | |
| 1092 | if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { |
| 1093 | // If the name is still dependent, just build a new dependent name type. |
| 1094 | if (!SemaRef.computeDeclContext(SS)) |
| 1095 | return SemaRef.Context.getDependentNameType(Keyword, |
| 1096 | QualifierLoc.getNestedNameSpecifier(), |
| 1097 | Id); |
| 1098 | } |
| 1099 | |
| 1100 | if (Keyword == ETK_None || Keyword == ETK_Typename) { |
| 1101 | return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, |
| 1102 | *Id, IdLoc, DeducedTSTContext); |
| 1103 | } |
| 1104 | |
| 1105 | TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); |
| 1106 | |
| 1107 | // We had a dependent elaborated-type-specifier that has been transformed |
| 1108 | // into a non-dependent elaborated-type-specifier. Find the tag we're |
| 1109 | // referring to. |
| 1110 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 1111 | DeclContext *DC = SemaRef.computeDeclContext(SS, false); |
| 1112 | if (!DC) |
| 1113 | return QualType(); |
| 1114 | |
| 1115 | if (SemaRef.RequireCompleteDeclContext(SS, DC)) |
| 1116 | return QualType(); |
| 1117 | |
| 1118 | TagDecl *Tag = nullptr; |
| 1119 | SemaRef.LookupQualifiedName(Result, DC); |
| 1120 | switch (Result.getResultKind()) { |
| 1121 | case LookupResult::NotFound: |
| 1122 | case LookupResult::NotFoundInCurrentInstantiation: |
| 1123 | break; |
| 1124 | |
| 1125 | case LookupResult::Found: |
| 1126 | Tag = Result.getAsSingle<TagDecl>(); |
| 1127 | break; |
| 1128 | |
| 1129 | case LookupResult::FoundOverloaded: |
| 1130 | case LookupResult::FoundUnresolvedValue: |
| 1131 | llvm_unreachable("Tag lookup cannot find non-tags" ); |
| 1132 | |
| 1133 | case LookupResult::Ambiguous: |
| 1134 | // Let the LookupResult structure handle ambiguities. |
| 1135 | return QualType(); |
| 1136 | } |
| 1137 | |
| 1138 | if (!Tag) { |
| 1139 | // Check where the name exists but isn't a tag type and use that to emit |
| 1140 | // better diagnostics. |
| 1141 | LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); |
| 1142 | SemaRef.LookupQualifiedName(Result, DC); |
| 1143 | switch (Result.getResultKind()) { |
| 1144 | case LookupResult::Found: |
| 1145 | case LookupResult::FoundOverloaded: |
| 1146 | case LookupResult::FoundUnresolvedValue: { |
| 1147 | NamedDecl *SomeDecl = Result.getRepresentativeDecl(); |
| 1148 | Sema::NonTagKind NTK = SemaRef.getNonTagTypeDeclKind(SomeDecl, Kind); |
| 1149 | SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << SomeDecl |
| 1150 | << NTK << Kind; |
| 1151 | SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); |
| 1152 | break; |
| 1153 | } |
| 1154 | default: |
| 1155 | SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) |
| 1156 | << Kind << Id << DC << QualifierLoc.getSourceRange(); |
| 1157 | break; |
| 1158 | } |
| 1159 | return QualType(); |
| 1160 | } |
| 1161 | |
| 1162 | if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, |
| 1163 | IdLoc, Id)) { |
| 1164 | SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; |
| 1165 | SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); |
| 1166 | return QualType(); |
| 1167 | } |
| 1168 | |
| 1169 | // Build the elaborated-type-specifier type. |
| 1170 | QualType T = SemaRef.Context.getTypeDeclType(Tag); |
| 1171 | return SemaRef.Context.getElaboratedType(Keyword, |
| 1172 | QualifierLoc.getNestedNameSpecifier(), |
| 1173 | T); |
| 1174 | } |
| 1175 | |
| 1176 | /// Build a new pack expansion type. |
| 1177 | /// |
| 1178 | /// By default, builds a new PackExpansionType type from the given pattern. |
| 1179 | /// Subclasses may override this routine to provide different behavior. |
| 1180 | QualType RebuildPackExpansionType(QualType Pattern, |
| 1181 | SourceRange PatternRange, |
| 1182 | SourceLocation EllipsisLoc, |
| 1183 | Optional<unsigned> NumExpansions) { |
| 1184 | return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, |
| 1185 | NumExpansions); |
| 1186 | } |
| 1187 | |
| 1188 | /// Build a new atomic type given its value type. |
| 1189 | /// |
| 1190 | /// By default, performs semantic analysis when building the atomic type. |
| 1191 | /// Subclasses may override this routine to provide different behavior. |
| 1192 | QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); |
| 1193 | |
| 1194 | /// Build a new pipe type given its value type. |
| 1195 | QualType RebuildPipeType(QualType ValueType, SourceLocation KWLoc, |
| 1196 | bool isReadPipe); |
| 1197 | |
| 1198 | /// Build an extended int given its value type. |
| 1199 | QualType RebuildExtIntType(bool IsUnsigned, unsigned NumBits, |
| 1200 | SourceLocation Loc); |
| 1201 | |
| 1202 | /// Build a dependent extended int given its value type. |
| 1203 | QualType RebuildDependentExtIntType(bool IsUnsigned, Expr *NumBitsExpr, |
| 1204 | SourceLocation Loc); |
| 1205 | |
| 1206 | /// Build a new template name given a nested name specifier, a flag |
| 1207 | /// indicating whether the "template" keyword was provided, and the template |
| 1208 | /// that the template name refers to. |
| 1209 | /// |
| 1210 | /// By default, builds the new template name directly. Subclasses may override |
| 1211 | /// this routine to provide different behavior. |
| 1212 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1213 | bool TemplateKW, |
| 1214 | TemplateDecl *Template); |
| 1215 | |
| 1216 | /// Build a new template name given a nested name specifier and the |
| 1217 | /// name that is referred to as a template. |
| 1218 | /// |
| 1219 | /// By default, performs semantic analysis to determine whether the name can |
| 1220 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1221 | /// template name. Subclasses may override this routine to provide different |
| 1222 | /// behavior. |
| 1223 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1224 | SourceLocation TemplateKWLoc, |
| 1225 | const IdentifierInfo &Name, |
| 1226 | SourceLocation NameLoc, QualType ObjectType, |
| 1227 | NamedDecl *FirstQualifierInScope, |
| 1228 | bool AllowInjectedClassName); |
| 1229 | |
| 1230 | /// Build a new template name given a nested name specifier and the |
| 1231 | /// overloaded operator name that is referred to as a template. |
| 1232 | /// |
| 1233 | /// By default, performs semantic analysis to determine whether the name can |
| 1234 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1235 | /// template name. Subclasses may override this routine to provide different |
| 1236 | /// behavior. |
| 1237 | TemplateName RebuildTemplateName(CXXScopeSpec &SS, |
| 1238 | SourceLocation TemplateKWLoc, |
| 1239 | OverloadedOperatorKind Operator, |
| 1240 | SourceLocation NameLoc, QualType ObjectType, |
| 1241 | bool AllowInjectedClassName); |
| 1242 | |
| 1243 | /// Build a new template name given a template template parameter pack |
| 1244 | /// and the |
| 1245 | /// |
| 1246 | /// By default, performs semantic analysis to determine whether the name can |
| 1247 | /// be resolved to a specific template, then builds the appropriate kind of |
| 1248 | /// template name. Subclasses may override this routine to provide different |
| 1249 | /// behavior. |
| 1250 | TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, |
| 1251 | const TemplateArgument &ArgPack) { |
| 1252 | return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); |
| 1253 | } |
| 1254 | |
| 1255 | /// Build a new compound statement. |
| 1256 | /// |
| 1257 | /// By default, performs semantic analysis to build the new statement. |
| 1258 | /// Subclasses may override this routine to provide different behavior. |
| 1259 | StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, |
| 1260 | MultiStmtArg Statements, |
| 1261 | SourceLocation RBraceLoc, |
| 1262 | bool IsStmtExpr) { |
| 1263 | return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, |
| 1264 | IsStmtExpr); |
| 1265 | } |
| 1266 | |
| 1267 | /// Build a new case statement. |
| 1268 | /// |
| 1269 | /// By default, performs semantic analysis to build the new statement. |
| 1270 | /// Subclasses may override this routine to provide different behavior. |
| 1271 | StmtResult RebuildCaseStmt(SourceLocation CaseLoc, |
| 1272 | Expr *LHS, |
| 1273 | SourceLocation EllipsisLoc, |
| 1274 | Expr *RHS, |
| 1275 | SourceLocation ColonLoc) { |
| 1276 | return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, |
| 1277 | ColonLoc); |
| 1278 | } |
| 1279 | |
| 1280 | /// Attach the body to a new case statement. |
| 1281 | /// |
| 1282 | /// By default, performs semantic analysis to build the new statement. |
| 1283 | /// Subclasses may override this routine to provide different behavior. |
| 1284 | StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { |
| 1285 | getSema().ActOnCaseStmtBody(S, Body); |
| 1286 | return S; |
| 1287 | } |
| 1288 | |
| 1289 | /// Build a new default statement. |
| 1290 | /// |
| 1291 | /// By default, performs semantic analysis to build the new statement. |
| 1292 | /// Subclasses may override this routine to provide different behavior. |
| 1293 | StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, |
| 1294 | SourceLocation ColonLoc, |
| 1295 | Stmt *SubStmt) { |
| 1296 | return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, |
| 1297 | /*CurScope=*/nullptr); |
| 1298 | } |
| 1299 | |
| 1300 | /// Build a new label statement. |
| 1301 | /// |
| 1302 | /// By default, performs semantic analysis to build the new statement. |
| 1303 | /// Subclasses may override this routine to provide different behavior. |
| 1304 | StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, |
| 1305 | SourceLocation ColonLoc, Stmt *SubStmt) { |
| 1306 | return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); |
| 1307 | } |
| 1308 | |
| 1309 | /// Build a new attributed statement. |
| 1310 | /// |
| 1311 | /// By default, performs semantic analysis to build the new statement. |
| 1312 | /// Subclasses may override this routine to provide different behavior. |
| 1313 | StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, |
| 1314 | ArrayRef<const Attr*> Attrs, |
| 1315 | Stmt *SubStmt) { |
| 1316 | return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); |
| 1317 | } |
| 1318 | |
| 1319 | /// Build a new "if" statement. |
| 1320 | /// |
| 1321 | /// By default, performs semantic analysis to build the new statement. |
| 1322 | /// Subclasses may override this routine to provide different behavior. |
| 1323 | StmtResult RebuildIfStmt(SourceLocation IfLoc, bool IsConstexpr, |
| 1324 | SourceLocation LParenLoc, Sema::ConditionResult Cond, |
| 1325 | SourceLocation RParenLoc, Stmt *Init, Stmt *Then, |
| 1326 | SourceLocation ElseLoc, Stmt *Else) { |
| 1327 | return getSema().ActOnIfStmt(IfLoc, IsConstexpr, LParenLoc, Init, Cond, |
| 1328 | RParenLoc, Then, ElseLoc, Else); |
| 1329 | } |
| 1330 | |
| 1331 | /// Start building a new switch statement. |
| 1332 | /// |
| 1333 | /// By default, performs semantic analysis to build the new statement. |
| 1334 | /// Subclasses may override this routine to provide different behavior. |
| 1335 | StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, |
| 1336 | SourceLocation LParenLoc, Stmt *Init, |
| 1337 | Sema::ConditionResult Cond, |
| 1338 | SourceLocation RParenLoc) { |
| 1339 | return getSema().ActOnStartOfSwitchStmt(SwitchLoc, LParenLoc, Init, Cond, |
| 1340 | RParenLoc); |
| 1341 | } |
| 1342 | |
| 1343 | /// Attach the body to the switch statement. |
| 1344 | /// |
| 1345 | /// By default, performs semantic analysis to build the new statement. |
| 1346 | /// Subclasses may override this routine to provide different behavior. |
| 1347 | StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, |
| 1348 | Stmt *Switch, Stmt *Body) { |
| 1349 | return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); |
| 1350 | } |
| 1351 | |
| 1352 | /// Build a new while statement. |
| 1353 | /// |
| 1354 | /// By default, performs semantic analysis to build the new statement. |
| 1355 | /// Subclasses may override this routine to provide different behavior. |
| 1356 | StmtResult RebuildWhileStmt(SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1357 | Sema::ConditionResult Cond, |
| 1358 | SourceLocation RParenLoc, Stmt *Body) { |
| 1359 | return getSema().ActOnWhileStmt(WhileLoc, LParenLoc, Cond, RParenLoc, Body); |
| 1360 | } |
| 1361 | |
| 1362 | /// Build a new do-while statement. |
| 1363 | /// |
| 1364 | /// By default, performs semantic analysis to build the new statement. |
| 1365 | /// Subclasses may override this routine to provide different behavior. |
| 1366 | StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, |
| 1367 | SourceLocation WhileLoc, SourceLocation LParenLoc, |
| 1368 | Expr *Cond, SourceLocation RParenLoc) { |
| 1369 | return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, |
| 1370 | Cond, RParenLoc); |
| 1371 | } |
| 1372 | |
| 1373 | /// Build a new for statement. |
| 1374 | /// |
| 1375 | /// By default, performs semantic analysis to build the new statement. |
| 1376 | /// Subclasses may override this routine to provide different behavior. |
| 1377 | StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, |
| 1378 | Stmt *Init, Sema::ConditionResult Cond, |
| 1379 | Sema::FullExprArg Inc, SourceLocation RParenLoc, |
| 1380 | Stmt *Body) { |
| 1381 | return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, |
| 1382 | Inc, RParenLoc, Body); |
| 1383 | } |
| 1384 | |
| 1385 | /// Build a new goto statement. |
| 1386 | /// |
| 1387 | /// By default, performs semantic analysis to build the new statement. |
| 1388 | /// Subclasses may override this routine to provide different behavior. |
| 1389 | StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, |
| 1390 | LabelDecl *Label) { |
| 1391 | return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); |
| 1392 | } |
| 1393 | |
| 1394 | /// Build a new indirect goto statement. |
| 1395 | /// |
| 1396 | /// By default, performs semantic analysis to build the new statement. |
| 1397 | /// Subclasses may override this routine to provide different behavior. |
| 1398 | StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, |
| 1399 | SourceLocation StarLoc, |
| 1400 | Expr *Target) { |
| 1401 | return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); |
| 1402 | } |
| 1403 | |
| 1404 | /// Build a new return statement. |
| 1405 | /// |
| 1406 | /// By default, performs semantic analysis to build the new statement. |
| 1407 | /// Subclasses may override this routine to provide different behavior. |
| 1408 | StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { |
| 1409 | return getSema().BuildReturnStmt(ReturnLoc, Result); |
| 1410 | } |
| 1411 | |
| 1412 | /// Build a new declaration statement. |
| 1413 | /// |
| 1414 | /// By default, performs semantic analysis to build the new statement. |
| 1415 | /// Subclasses may override this routine to provide different behavior. |
| 1416 | StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls, |
| 1417 | SourceLocation StartLoc, SourceLocation EndLoc) { |
| 1418 | Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls); |
| 1419 | return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); |
| 1420 | } |
| 1421 | |
| 1422 | /// Build a new inline asm statement. |
| 1423 | /// |
| 1424 | /// By default, performs semantic analysis to build the new statement. |
| 1425 | /// Subclasses may override this routine to provide different behavior. |
| 1426 | StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, |
| 1427 | bool IsVolatile, unsigned NumOutputs, |
| 1428 | unsigned NumInputs, IdentifierInfo **Names, |
| 1429 | MultiExprArg Constraints, MultiExprArg Exprs, |
| 1430 | Expr *AsmString, MultiExprArg Clobbers, |
| 1431 | unsigned NumLabels, |
| 1432 | SourceLocation RParenLoc) { |
| 1433 | return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, |
| 1434 | NumInputs, Names, Constraints, Exprs, |
| 1435 | AsmString, Clobbers, NumLabels, RParenLoc); |
| 1436 | } |
| 1437 | |
| 1438 | /// Build a new MS style inline asm statement. |
| 1439 | /// |
| 1440 | /// By default, performs semantic analysis to build the new statement. |
| 1441 | /// Subclasses may override this routine to provide different behavior. |
| 1442 | StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc, |
| 1443 | ArrayRef<Token> AsmToks, |
| 1444 | StringRef AsmString, |
| 1445 | unsigned NumOutputs, unsigned NumInputs, |
| 1446 | ArrayRef<StringRef> Constraints, |
| 1447 | ArrayRef<StringRef> Clobbers, |
| 1448 | ArrayRef<Expr*> Exprs, |
| 1449 | SourceLocation EndLoc) { |
| 1450 | return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString, |
| 1451 | NumOutputs, NumInputs, |
| 1452 | Constraints, Clobbers, Exprs, EndLoc); |
| 1453 | } |
| 1454 | |
| 1455 | /// Build a new co_return statement. |
| 1456 | /// |
| 1457 | /// By default, performs semantic analysis to build the new statement. |
| 1458 | /// Subclasses may override this routine to provide different behavior. |
| 1459 | StmtResult RebuildCoreturnStmt(SourceLocation CoreturnLoc, Expr *Result, |
| 1460 | bool IsImplicit) { |
| 1461 | return getSema().BuildCoreturnStmt(CoreturnLoc, Result, IsImplicit); |
| 1462 | } |
| 1463 | |
| 1464 | /// Build a new co_await expression. |
| 1465 | /// |
| 1466 | /// By default, performs semantic analysis to build the new expression. |
| 1467 | /// Subclasses may override this routine to provide different behavior. |
| 1468 | ExprResult RebuildCoawaitExpr(SourceLocation CoawaitLoc, Expr *Result, |
| 1469 | bool IsImplicit) { |
| 1470 | return getSema().BuildResolvedCoawaitExpr(CoawaitLoc, Result, IsImplicit); |
| 1471 | } |
| 1472 | |
| 1473 | /// Build a new co_await expression. |
| 1474 | /// |
| 1475 | /// By default, performs semantic analysis to build the new expression. |
| 1476 | /// Subclasses may override this routine to provide different behavior. |
| 1477 | ExprResult RebuildDependentCoawaitExpr(SourceLocation CoawaitLoc, |
| 1478 | Expr *Result, |
| 1479 | UnresolvedLookupExpr *Lookup) { |
| 1480 | return getSema().BuildUnresolvedCoawaitExpr(CoawaitLoc, Result, Lookup); |
| 1481 | } |
| 1482 | |
| 1483 | /// Build a new co_yield expression. |
| 1484 | /// |
| 1485 | /// By default, performs semantic analysis to build the new expression. |
| 1486 | /// Subclasses may override this routine to provide different behavior. |
| 1487 | ExprResult RebuildCoyieldExpr(SourceLocation CoyieldLoc, Expr *Result) { |
| 1488 | return getSema().BuildCoyieldExpr(CoyieldLoc, Result); |
| 1489 | } |
| 1490 | |
| 1491 | StmtResult RebuildCoroutineBodyStmt(CoroutineBodyStmt::CtorArgs Args) { |
| 1492 | return getSema().BuildCoroutineBodyStmt(Args); |
| 1493 | } |
| 1494 | |
| 1495 | /// Build a new Objective-C \@try statement. |
| 1496 | /// |
| 1497 | /// By default, performs semantic analysis to build the new statement. |
| 1498 | /// Subclasses may override this routine to provide different behavior. |
| 1499 | StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, |
| 1500 | Stmt *TryBody, |
| 1501 | MultiStmtArg CatchStmts, |
| 1502 | Stmt *Finally) { |
| 1503 | return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, |
| 1504 | Finally); |
| 1505 | } |
| 1506 | |
| 1507 | /// Rebuild an Objective-C exception declaration. |
| 1508 | /// |
| 1509 | /// By default, performs semantic analysis to build the new declaration. |
| 1510 | /// Subclasses may override this routine to provide different behavior. |
| 1511 | VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, |
| 1512 | TypeSourceInfo *TInfo, QualType T) { |
| 1513 | return getSema().BuildObjCExceptionDecl(TInfo, T, |
| 1514 | ExceptionDecl->getInnerLocStart(), |
| 1515 | ExceptionDecl->getLocation(), |
| 1516 | ExceptionDecl->getIdentifier()); |
| 1517 | } |
| 1518 | |
| 1519 | /// Build a new Objective-C \@catch statement. |
| 1520 | /// |
| 1521 | /// By default, performs semantic analysis to build the new statement. |
| 1522 | /// Subclasses may override this routine to provide different behavior. |
| 1523 | StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, |
| 1524 | SourceLocation RParenLoc, |
| 1525 | VarDecl *Var, |
| 1526 | Stmt *Body) { |
| 1527 | return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, |
| 1528 | Var, Body); |
| 1529 | } |
| 1530 | |
| 1531 | /// Build a new Objective-C \@finally statement. |
| 1532 | /// |
| 1533 | /// By default, performs semantic analysis to build the new statement. |
| 1534 | /// Subclasses may override this routine to provide different behavior. |
| 1535 | StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, |
| 1536 | Stmt *Body) { |
| 1537 | return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); |
| 1538 | } |
| 1539 | |
| 1540 | /// Build a new Objective-C \@throw statement. |
| 1541 | /// |
| 1542 | /// By default, performs semantic analysis to build the new statement. |
| 1543 | /// Subclasses may override this routine to provide different behavior. |
| 1544 | StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, |
| 1545 | Expr *Operand) { |
| 1546 | return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); |
| 1547 | } |
| 1548 | |
| 1549 | /// Build a new OpenMP executable directive. |
| 1550 | /// |
| 1551 | /// By default, performs semantic analysis to build the new statement. |
| 1552 | /// Subclasses may override this routine to provide different behavior. |
| 1553 | StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind, |
| 1554 | DeclarationNameInfo DirName, |
| 1555 | OpenMPDirectiveKind CancelRegion, |
| 1556 | ArrayRef<OMPClause *> Clauses, |
| 1557 | Stmt *AStmt, SourceLocation StartLoc, |
| 1558 | SourceLocation EndLoc) { |
| 1559 | return getSema().ActOnOpenMPExecutableDirective( |
| 1560 | Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc); |
| 1561 | } |
| 1562 | |
| 1563 | /// Build a new OpenMP 'if' clause. |
| 1564 | /// |
| 1565 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1566 | /// Subclasses may override this routine to provide different behavior. |
| 1567 | OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier, |
| 1568 | Expr *Condition, SourceLocation StartLoc, |
| 1569 | SourceLocation LParenLoc, |
| 1570 | SourceLocation NameModifierLoc, |
| 1571 | SourceLocation ColonLoc, |
| 1572 | SourceLocation EndLoc) { |
| 1573 | return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc, |
| 1574 | LParenLoc, NameModifierLoc, ColonLoc, |
| 1575 | EndLoc); |
| 1576 | } |
| 1577 | |
| 1578 | /// Build a new OpenMP 'final' clause. |
| 1579 | /// |
| 1580 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1581 | /// Subclasses may override this routine to provide different behavior. |
| 1582 | OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc, |
| 1583 | SourceLocation LParenLoc, |
| 1584 | SourceLocation EndLoc) { |
| 1585 | return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc, |
| 1586 | EndLoc); |
| 1587 | } |
| 1588 | |
| 1589 | /// Build a new OpenMP 'num_threads' clause. |
| 1590 | /// |
| 1591 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1592 | /// Subclasses may override this routine to provide different behavior. |
| 1593 | OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads, |
| 1594 | SourceLocation StartLoc, |
| 1595 | SourceLocation LParenLoc, |
| 1596 | SourceLocation EndLoc) { |
| 1597 | return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc, |
| 1598 | LParenLoc, EndLoc); |
| 1599 | } |
| 1600 | |
| 1601 | /// Build a new OpenMP 'safelen' clause. |
| 1602 | /// |
| 1603 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1604 | /// Subclasses may override this routine to provide different behavior. |
| 1605 | OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc, |
| 1606 | SourceLocation LParenLoc, |
| 1607 | SourceLocation EndLoc) { |
| 1608 | return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1609 | } |
| 1610 | |
| 1611 | /// Build a new OpenMP 'simdlen' clause. |
| 1612 | /// |
| 1613 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1614 | /// Subclasses may override this routine to provide different behavior. |
| 1615 | OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc, |
| 1616 | SourceLocation LParenLoc, |
| 1617 | SourceLocation EndLoc) { |
| 1618 | return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc); |
| 1619 | } |
| 1620 | |
| 1621 | /// Build a new OpenMP 'allocator' clause. |
| 1622 | /// |
| 1623 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1624 | /// Subclasses may override this routine to provide different behavior. |
| 1625 | OMPClause *RebuildOMPAllocatorClause(Expr *A, SourceLocation StartLoc, |
| 1626 | SourceLocation LParenLoc, |
| 1627 | SourceLocation EndLoc) { |
| 1628 | return getSema().ActOnOpenMPAllocatorClause(A, StartLoc, LParenLoc, EndLoc); |
| 1629 | } |
| 1630 | |
| 1631 | /// Build a new OpenMP 'collapse' clause. |
| 1632 | /// |
| 1633 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1634 | /// Subclasses may override this routine to provide different behavior. |
| 1635 | OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc, |
| 1636 | SourceLocation LParenLoc, |
| 1637 | SourceLocation EndLoc) { |
| 1638 | return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc, |
| 1639 | EndLoc); |
| 1640 | } |
| 1641 | |
| 1642 | /// Build a new OpenMP 'default' clause. |
| 1643 | /// |
| 1644 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1645 | /// Subclasses may override this routine to provide different behavior. |
| 1646 | OMPClause *RebuildOMPDefaultClause(DefaultKind Kind, SourceLocation KindKwLoc, |
| 1647 | SourceLocation StartLoc, |
| 1648 | SourceLocation LParenLoc, |
| 1649 | SourceLocation EndLoc) { |
| 1650 | return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc, |
| 1651 | StartLoc, LParenLoc, EndLoc); |
| 1652 | } |
| 1653 | |
| 1654 | /// Build a new OpenMP 'proc_bind' clause. |
| 1655 | /// |
| 1656 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1657 | /// Subclasses may override this routine to provide different behavior. |
| 1658 | OMPClause *RebuildOMPProcBindClause(ProcBindKind Kind, |
| 1659 | SourceLocation KindKwLoc, |
| 1660 | SourceLocation StartLoc, |
| 1661 | SourceLocation LParenLoc, |
| 1662 | SourceLocation EndLoc) { |
| 1663 | return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc, |
| 1664 | StartLoc, LParenLoc, EndLoc); |
| 1665 | } |
| 1666 | |
| 1667 | /// Build a new OpenMP 'schedule' clause. |
| 1668 | /// |
| 1669 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1670 | /// Subclasses may override this routine to provide different behavior. |
| 1671 | OMPClause *RebuildOMPScheduleClause( |
| 1672 | OpenMPScheduleClauseModifier M1, OpenMPScheduleClauseModifier M2, |
| 1673 | OpenMPScheduleClauseKind Kind, Expr *ChunkSize, SourceLocation StartLoc, |
| 1674 | SourceLocation LParenLoc, SourceLocation M1Loc, SourceLocation M2Loc, |
| 1675 | SourceLocation KindLoc, SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 1676 | return getSema().ActOnOpenMPScheduleClause( |
| 1677 | M1, M2, Kind, ChunkSize, StartLoc, LParenLoc, M1Loc, M2Loc, KindLoc, |
| 1678 | CommaLoc, EndLoc); |
| 1679 | } |
| 1680 | |
| 1681 | /// Build a new OpenMP 'ordered' clause. |
| 1682 | /// |
| 1683 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1684 | /// Subclasses may override this routine to provide different behavior. |
| 1685 | OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc, |
| 1686 | SourceLocation EndLoc, |
| 1687 | SourceLocation LParenLoc, Expr *Num) { |
| 1688 | return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num); |
| 1689 | } |
| 1690 | |
| 1691 | /// Build a new OpenMP 'private' clause. |
| 1692 | /// |
| 1693 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1694 | /// Subclasses may override this routine to provide different behavior. |
| 1695 | OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList, |
| 1696 | SourceLocation StartLoc, |
| 1697 | SourceLocation LParenLoc, |
| 1698 | SourceLocation EndLoc) { |
| 1699 | return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc, |
| 1700 | EndLoc); |
| 1701 | } |
| 1702 | |
| 1703 | /// Build a new OpenMP 'firstprivate' clause. |
| 1704 | /// |
| 1705 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1706 | /// Subclasses may override this routine to provide different behavior. |
| 1707 | OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList, |
| 1708 | SourceLocation StartLoc, |
| 1709 | SourceLocation LParenLoc, |
| 1710 | SourceLocation EndLoc) { |
| 1711 | return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc, |
| 1712 | EndLoc); |
| 1713 | } |
| 1714 | |
| 1715 | /// Build a new OpenMP 'lastprivate' clause. |
| 1716 | /// |
| 1717 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1718 | /// Subclasses may override this routine to provide different behavior. |
| 1719 | OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList, |
| 1720 | OpenMPLastprivateModifier LPKind, |
| 1721 | SourceLocation LPKindLoc, |
| 1722 | SourceLocation ColonLoc, |
| 1723 | SourceLocation StartLoc, |
| 1724 | SourceLocation LParenLoc, |
| 1725 | SourceLocation EndLoc) { |
| 1726 | return getSema().ActOnOpenMPLastprivateClause( |
| 1727 | VarList, LPKind, LPKindLoc, ColonLoc, StartLoc, LParenLoc, EndLoc); |
| 1728 | } |
| 1729 | |
| 1730 | /// Build a new OpenMP 'shared' clause. |
| 1731 | /// |
| 1732 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1733 | /// Subclasses may override this routine to provide different behavior. |
| 1734 | OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList, |
| 1735 | SourceLocation StartLoc, |
| 1736 | SourceLocation LParenLoc, |
| 1737 | SourceLocation EndLoc) { |
| 1738 | return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc, |
| 1739 | EndLoc); |
| 1740 | } |
| 1741 | |
| 1742 | /// Build a new OpenMP 'reduction' clause. |
| 1743 | /// |
| 1744 | /// By default, performs semantic analysis to build the new statement. |
| 1745 | /// Subclasses may override this routine to provide different behavior. |
| 1746 | OMPClause *RebuildOMPReductionClause( |
| 1747 | ArrayRef<Expr *> VarList, OpenMPReductionClauseModifier Modifier, |
| 1748 | SourceLocation StartLoc, SourceLocation LParenLoc, |
| 1749 | SourceLocation ModifierLoc, SourceLocation ColonLoc, |
| 1750 | SourceLocation EndLoc, CXXScopeSpec &ReductionIdScopeSpec, |
| 1751 | const DeclarationNameInfo &ReductionId, |
| 1752 | ArrayRef<Expr *> UnresolvedReductions) { |
| 1753 | return getSema().ActOnOpenMPReductionClause( |
| 1754 | VarList, Modifier, StartLoc, LParenLoc, ModifierLoc, ColonLoc, EndLoc, |
| 1755 | ReductionIdScopeSpec, ReductionId, UnresolvedReductions); |
| 1756 | } |
| 1757 | |
| 1758 | /// Build a new OpenMP 'task_reduction' clause. |
| 1759 | /// |
| 1760 | /// By default, performs semantic analysis to build the new statement. |
| 1761 | /// Subclasses may override this routine to provide different behavior. |
| 1762 | OMPClause *RebuildOMPTaskReductionClause( |
| 1763 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1764 | SourceLocation LParenLoc, SourceLocation ColonLoc, SourceLocation EndLoc, |
| 1765 | CXXScopeSpec &ReductionIdScopeSpec, |
| 1766 | const DeclarationNameInfo &ReductionId, |
| 1767 | ArrayRef<Expr *> UnresolvedReductions) { |
| 1768 | return getSema().ActOnOpenMPTaskReductionClause( |
| 1769 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1770 | ReductionId, UnresolvedReductions); |
| 1771 | } |
| 1772 | |
| 1773 | /// Build a new OpenMP 'in_reduction' clause. |
| 1774 | /// |
| 1775 | /// By default, performs semantic analysis to build the new statement. |
| 1776 | /// Subclasses may override this routine to provide different behavior. |
| 1777 | OMPClause * |
| 1778 | RebuildOMPInReductionClause(ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1779 | SourceLocation LParenLoc, SourceLocation ColonLoc, |
| 1780 | SourceLocation EndLoc, |
| 1781 | CXXScopeSpec &ReductionIdScopeSpec, |
| 1782 | const DeclarationNameInfo &ReductionId, |
| 1783 | ArrayRef<Expr *> UnresolvedReductions) { |
| 1784 | return getSema().ActOnOpenMPInReductionClause( |
| 1785 | VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec, |
| 1786 | ReductionId, UnresolvedReductions); |
| 1787 | } |
| 1788 | |
| 1789 | /// Build a new OpenMP 'linear' clause. |
| 1790 | /// |
| 1791 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1792 | /// Subclasses may override this routine to provide different behavior. |
| 1793 | OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step, |
| 1794 | SourceLocation StartLoc, |
| 1795 | SourceLocation LParenLoc, |
| 1796 | OpenMPLinearClauseKind Modifier, |
| 1797 | SourceLocation ModifierLoc, |
| 1798 | SourceLocation ColonLoc, |
| 1799 | SourceLocation EndLoc) { |
| 1800 | return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc, |
| 1801 | Modifier, ModifierLoc, ColonLoc, |
| 1802 | EndLoc); |
| 1803 | } |
| 1804 | |
| 1805 | /// Build a new OpenMP 'aligned' clause. |
| 1806 | /// |
| 1807 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1808 | /// Subclasses may override this routine to provide different behavior. |
| 1809 | OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment, |
| 1810 | SourceLocation StartLoc, |
| 1811 | SourceLocation LParenLoc, |
| 1812 | SourceLocation ColonLoc, |
| 1813 | SourceLocation EndLoc) { |
| 1814 | return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc, |
| 1815 | LParenLoc, ColonLoc, EndLoc); |
| 1816 | } |
| 1817 | |
| 1818 | /// Build a new OpenMP 'copyin' clause. |
| 1819 | /// |
| 1820 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1821 | /// Subclasses may override this routine to provide different behavior. |
| 1822 | OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList, |
| 1823 | SourceLocation StartLoc, |
| 1824 | SourceLocation LParenLoc, |
| 1825 | SourceLocation EndLoc) { |
| 1826 | return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc, |
| 1827 | EndLoc); |
| 1828 | } |
| 1829 | |
| 1830 | /// Build a new OpenMP 'copyprivate' clause. |
| 1831 | /// |
| 1832 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1833 | /// Subclasses may override this routine to provide different behavior. |
| 1834 | OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList, |
| 1835 | SourceLocation StartLoc, |
| 1836 | SourceLocation LParenLoc, |
| 1837 | SourceLocation EndLoc) { |
| 1838 | return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc, |
| 1839 | EndLoc); |
| 1840 | } |
| 1841 | |
| 1842 | /// Build a new OpenMP 'flush' pseudo clause. |
| 1843 | /// |
| 1844 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1845 | /// Subclasses may override this routine to provide different behavior. |
| 1846 | OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList, |
| 1847 | SourceLocation StartLoc, |
| 1848 | SourceLocation LParenLoc, |
| 1849 | SourceLocation EndLoc) { |
| 1850 | return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc, |
| 1851 | EndLoc); |
| 1852 | } |
| 1853 | |
| 1854 | /// Build a new OpenMP 'depobj' pseudo clause. |
| 1855 | /// |
| 1856 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1857 | /// Subclasses may override this routine to provide different behavior. |
| 1858 | OMPClause *RebuildOMPDepobjClause(Expr *Depobj, SourceLocation StartLoc, |
| 1859 | SourceLocation LParenLoc, |
| 1860 | SourceLocation EndLoc) { |
| 1861 | return getSema().ActOnOpenMPDepobjClause(Depobj, StartLoc, LParenLoc, |
| 1862 | EndLoc); |
| 1863 | } |
| 1864 | |
| 1865 | /// Build a new OpenMP 'depend' pseudo clause. |
| 1866 | /// |
| 1867 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1868 | /// Subclasses may override this routine to provide different behavior. |
| 1869 | OMPClause * |
| 1870 | RebuildOMPDependClause(Expr *DepModifier, OpenMPDependClauseKind DepKind, |
| 1871 | SourceLocation DepLoc, SourceLocation ColonLoc, |
| 1872 | ArrayRef<Expr *> VarList, SourceLocation StartLoc, |
| 1873 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 1874 | return getSema().ActOnOpenMPDependClause(DepModifier, DepKind, DepLoc, |
| 1875 | ColonLoc, VarList, StartLoc, |
| 1876 | LParenLoc, EndLoc); |
| 1877 | } |
| 1878 | |
| 1879 | /// Build a new OpenMP 'device' clause. |
| 1880 | /// |
| 1881 | /// By default, performs semantic analysis to build the new statement. |
| 1882 | /// Subclasses may override this routine to provide different behavior. |
| 1883 | OMPClause *RebuildOMPDeviceClause(OpenMPDeviceClauseModifier Modifier, |
| 1884 | Expr *Device, SourceLocation StartLoc, |
| 1885 | SourceLocation LParenLoc, |
| 1886 | SourceLocation ModifierLoc, |
| 1887 | SourceLocation EndLoc) { |
| 1888 | return getSema().ActOnOpenMPDeviceClause(Modifier, Device, StartLoc, |
| 1889 | LParenLoc, ModifierLoc, EndLoc); |
| 1890 | } |
| 1891 | |
| 1892 | /// Build a new OpenMP 'map' clause. |
| 1893 | /// |
| 1894 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1895 | /// Subclasses may override this routine to provide different behavior. |
| 1896 | OMPClause *RebuildOMPMapClause( |
| 1897 | ArrayRef<OpenMPMapModifierKind> MapTypeModifiers, |
| 1898 | ArrayRef<SourceLocation> MapTypeModifiersLoc, |
| 1899 | CXXScopeSpec MapperIdScopeSpec, DeclarationNameInfo MapperId, |
| 1900 | OpenMPMapClauseKind MapType, bool IsMapTypeImplicit, |
| 1901 | SourceLocation MapLoc, SourceLocation ColonLoc, ArrayRef<Expr *> VarList, |
| 1902 | const OMPVarListLocTy &Locs, ArrayRef<Expr *> UnresolvedMappers) { |
| 1903 | return getSema().ActOnOpenMPMapClause(MapTypeModifiers, MapTypeModifiersLoc, |
| 1904 | MapperIdScopeSpec, MapperId, MapType, |
| 1905 | IsMapTypeImplicit, MapLoc, ColonLoc, |
| 1906 | VarList, Locs, UnresolvedMappers); |
| 1907 | } |
| 1908 | |
| 1909 | /// Build a new OpenMP 'allocate' clause. |
| 1910 | /// |
| 1911 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 1912 | /// Subclasses may override this routine to provide different behavior. |
| 1913 | OMPClause *RebuildOMPAllocateClause(Expr *Allocate, ArrayRef<Expr *> VarList, |
| 1914 | SourceLocation StartLoc, |
| 1915 | SourceLocation LParenLoc, |
| 1916 | SourceLocation ColonLoc, |
| 1917 | SourceLocation EndLoc) { |
| 1918 | return getSema().ActOnOpenMPAllocateClause(Allocate, VarList, StartLoc, |
| 1919 | LParenLoc, ColonLoc, EndLoc); |
| 1920 | } |
| 1921 | |
| 1922 | /// Build a new OpenMP 'num_teams' clause. |
| 1923 | /// |
| 1924 | /// By default, performs semantic analysis to build the new statement. |
| 1925 | /// Subclasses may override this routine to provide different behavior. |
| 1926 | OMPClause *RebuildOMPNumTeamsClause(Expr *NumTeams, SourceLocation StartLoc, |
| 1927 | SourceLocation LParenLoc, |
| 1928 | SourceLocation EndLoc) { |
| 1929 | return getSema().ActOnOpenMPNumTeamsClause(NumTeams, StartLoc, LParenLoc, |
| 1930 | EndLoc); |
| 1931 | } |
| 1932 | |
| 1933 | /// Build a new OpenMP 'thread_limit' clause. |
| 1934 | /// |
| 1935 | /// By default, performs semantic analysis to build the new statement. |
| 1936 | /// Subclasses may override this routine to provide different behavior. |
| 1937 | OMPClause *RebuildOMPThreadLimitClause(Expr *ThreadLimit, |
| 1938 | SourceLocation StartLoc, |
| 1939 | SourceLocation LParenLoc, |
| 1940 | SourceLocation EndLoc) { |
| 1941 | return getSema().ActOnOpenMPThreadLimitClause(ThreadLimit, StartLoc, |
| 1942 | LParenLoc, EndLoc); |
| 1943 | } |
| 1944 | |
| 1945 | /// Build a new OpenMP 'priority' clause. |
| 1946 | /// |
| 1947 | /// By default, performs semantic analysis to build the new statement. |
| 1948 | /// Subclasses may override this routine to provide different behavior. |
| 1949 | OMPClause *RebuildOMPPriorityClause(Expr *Priority, SourceLocation StartLoc, |
| 1950 | SourceLocation LParenLoc, |
| 1951 | SourceLocation EndLoc) { |
| 1952 | return getSema().ActOnOpenMPPriorityClause(Priority, StartLoc, LParenLoc, |
| 1953 | EndLoc); |
| 1954 | } |
| 1955 | |
| 1956 | /// Build a new OpenMP 'grainsize' clause. |
| 1957 | /// |
| 1958 | /// By default, performs semantic analysis to build the new statement. |
| 1959 | /// Subclasses may override this routine to provide different behavior. |
| 1960 | OMPClause *RebuildOMPGrainsizeClause(Expr *Grainsize, SourceLocation StartLoc, |
| 1961 | SourceLocation LParenLoc, |
| 1962 | SourceLocation EndLoc) { |
| 1963 | return getSema().ActOnOpenMPGrainsizeClause(Grainsize, StartLoc, LParenLoc, |
| 1964 | EndLoc); |
| 1965 | } |
| 1966 | |
| 1967 | /// Build a new OpenMP 'num_tasks' clause. |
| 1968 | /// |
| 1969 | /// By default, performs semantic analysis to build the new statement. |
| 1970 | /// Subclasses may override this routine to provide different behavior. |
| 1971 | OMPClause *RebuildOMPNumTasksClause(Expr *NumTasks, SourceLocation StartLoc, |
| 1972 | SourceLocation LParenLoc, |
| 1973 | SourceLocation EndLoc) { |
| 1974 | return getSema().ActOnOpenMPNumTasksClause(NumTasks, StartLoc, LParenLoc, |
| 1975 | EndLoc); |
| 1976 | } |
| 1977 | |
| 1978 | /// Build a new OpenMP 'hint' clause. |
| 1979 | /// |
| 1980 | /// By default, performs semantic analysis to build the new statement. |
| 1981 | /// Subclasses may override this routine to provide different behavior. |
| 1982 | OMPClause *RebuildOMPHintClause(Expr *Hint, SourceLocation StartLoc, |
| 1983 | SourceLocation LParenLoc, |
| 1984 | SourceLocation EndLoc) { |
| 1985 | return getSema().ActOnOpenMPHintClause(Hint, StartLoc, LParenLoc, EndLoc); |
| 1986 | } |
| 1987 | |
| 1988 | /// Build a new OpenMP 'detach' clause. |
| 1989 | /// |
| 1990 | /// By default, performs semantic analysis to build the new statement. |
| 1991 | /// Subclasses may override this routine to provide different behavior. |
| 1992 | OMPClause *RebuildOMPDetachClause(Expr *Evt, SourceLocation StartLoc, |
| 1993 | SourceLocation LParenLoc, |
| 1994 | SourceLocation EndLoc) { |
| 1995 | return getSema().ActOnOpenMPDetachClause(Evt, StartLoc, LParenLoc, EndLoc); |
| 1996 | } |
| 1997 | |
| 1998 | /// Build a new OpenMP 'dist_schedule' clause. |
| 1999 | /// |
| 2000 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2001 | /// Subclasses may override this routine to provide different behavior. |
| 2002 | OMPClause * |
| 2003 | RebuildOMPDistScheduleClause(OpenMPDistScheduleClauseKind Kind, |
| 2004 | Expr *ChunkSize, SourceLocation StartLoc, |
| 2005 | SourceLocation LParenLoc, SourceLocation KindLoc, |
| 2006 | SourceLocation CommaLoc, SourceLocation EndLoc) { |
| 2007 | return getSema().ActOnOpenMPDistScheduleClause( |
| 2008 | Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc); |
| 2009 | } |
| 2010 | |
| 2011 | /// Build a new OpenMP 'to' clause. |
| 2012 | /// |
| 2013 | /// By default, performs semantic analysis to build the new statement. |
| 2014 | /// Subclasses may override this routine to provide different behavior. |
| 2015 | OMPClause * |
| 2016 | RebuildOMPToClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
| 2017 | ArrayRef<SourceLocation> MotionModifiersLoc, |
| 2018 | CXXScopeSpec &MapperIdScopeSpec, |
| 2019 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
| 2020 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
| 2021 | ArrayRef<Expr *> UnresolvedMappers) { |
| 2022 | return getSema().ActOnOpenMPToClause(MotionModifiers, MotionModifiersLoc, |
| 2023 | MapperIdScopeSpec, MapperId, ColonLoc, |
| 2024 | VarList, Locs, UnresolvedMappers); |
| 2025 | } |
| 2026 | |
| 2027 | /// Build a new OpenMP 'from' clause. |
| 2028 | /// |
| 2029 | /// By default, performs semantic analysis to build the new statement. |
| 2030 | /// Subclasses may override this routine to provide different behavior. |
| 2031 | OMPClause * |
| 2032 | RebuildOMPFromClause(ArrayRef<OpenMPMotionModifierKind> MotionModifiers, |
| 2033 | ArrayRef<SourceLocation> MotionModifiersLoc, |
| 2034 | CXXScopeSpec &MapperIdScopeSpec, |
| 2035 | DeclarationNameInfo &MapperId, SourceLocation ColonLoc, |
| 2036 | ArrayRef<Expr *> VarList, const OMPVarListLocTy &Locs, |
| 2037 | ArrayRef<Expr *> UnresolvedMappers) { |
| 2038 | return getSema().ActOnOpenMPFromClause( |
| 2039 | MotionModifiers, MotionModifiersLoc, MapperIdScopeSpec, MapperId, |
| 2040 | ColonLoc, VarList, Locs, UnresolvedMappers); |
| 2041 | } |
| 2042 | |
| 2043 | /// Build a new OpenMP 'use_device_ptr' clause. |
| 2044 | /// |
| 2045 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2046 | /// Subclasses may override this routine to provide different behavior. |
| 2047 | OMPClause *RebuildOMPUseDevicePtrClause(ArrayRef<Expr *> VarList, |
| 2048 | const OMPVarListLocTy &Locs) { |
| 2049 | return getSema().ActOnOpenMPUseDevicePtrClause(VarList, Locs); |
| 2050 | } |
| 2051 | |
| 2052 | /// Build a new OpenMP 'use_device_addr' clause. |
| 2053 | /// |
| 2054 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2055 | /// Subclasses may override this routine to provide different behavior. |
| 2056 | OMPClause *RebuildOMPUseDeviceAddrClause(ArrayRef<Expr *> VarList, |
| 2057 | const OMPVarListLocTy &Locs) { |
| 2058 | return getSema().ActOnOpenMPUseDeviceAddrClause(VarList, Locs); |
| 2059 | } |
| 2060 | |
| 2061 | /// Build a new OpenMP 'is_device_ptr' clause. |
| 2062 | /// |
| 2063 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2064 | /// Subclasses may override this routine to provide different behavior. |
| 2065 | OMPClause *RebuildOMPIsDevicePtrClause(ArrayRef<Expr *> VarList, |
| 2066 | const OMPVarListLocTy &Locs) { |
| 2067 | return getSema().ActOnOpenMPIsDevicePtrClause(VarList, Locs); |
| 2068 | } |
| 2069 | |
| 2070 | /// Build a new OpenMP 'defaultmap' clause. |
| 2071 | /// |
| 2072 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2073 | /// Subclasses may override this routine to provide different behavior. |
| 2074 | OMPClause *RebuildOMPDefaultmapClause(OpenMPDefaultmapClauseModifier M, |
| 2075 | OpenMPDefaultmapClauseKind Kind, |
| 2076 | SourceLocation StartLoc, |
| 2077 | SourceLocation LParenLoc, |
| 2078 | SourceLocation MLoc, |
| 2079 | SourceLocation KindLoc, |
| 2080 | SourceLocation EndLoc) { |
| 2081 | return getSema().ActOnOpenMPDefaultmapClause(M, Kind, StartLoc, LParenLoc, |
| 2082 | MLoc, KindLoc, EndLoc); |
| 2083 | } |
| 2084 | |
| 2085 | /// Build a new OpenMP 'nontemporal' clause. |
| 2086 | /// |
| 2087 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2088 | /// Subclasses may override this routine to provide different behavior. |
| 2089 | OMPClause *RebuildOMPNontemporalClause(ArrayRef<Expr *> VarList, |
| 2090 | SourceLocation StartLoc, |
| 2091 | SourceLocation LParenLoc, |
| 2092 | SourceLocation EndLoc) { |
| 2093 | return getSema().ActOnOpenMPNontemporalClause(VarList, StartLoc, LParenLoc, |
| 2094 | EndLoc); |
| 2095 | } |
| 2096 | |
| 2097 | /// Build a new OpenMP 'inclusive' clause. |
| 2098 | /// |
| 2099 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2100 | /// Subclasses may override this routine to provide different behavior. |
| 2101 | OMPClause *RebuildOMPInclusiveClause(ArrayRef<Expr *> VarList, |
| 2102 | SourceLocation StartLoc, |
| 2103 | SourceLocation LParenLoc, |
| 2104 | SourceLocation EndLoc) { |
| 2105 | return getSema().ActOnOpenMPInclusiveClause(VarList, StartLoc, LParenLoc, |
| 2106 | EndLoc); |
| 2107 | } |
| 2108 | |
| 2109 | /// Build a new OpenMP 'exclusive' clause. |
| 2110 | /// |
| 2111 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2112 | /// Subclasses may override this routine to provide different behavior. |
| 2113 | OMPClause *RebuildOMPExclusiveClause(ArrayRef<Expr *> VarList, |
| 2114 | SourceLocation StartLoc, |
| 2115 | SourceLocation LParenLoc, |
| 2116 | SourceLocation EndLoc) { |
| 2117 | return getSema().ActOnOpenMPExclusiveClause(VarList, StartLoc, LParenLoc, |
| 2118 | EndLoc); |
| 2119 | } |
| 2120 | |
| 2121 | /// Build a new OpenMP 'uses_allocators' clause. |
| 2122 | /// |
| 2123 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2124 | /// Subclasses may override this routine to provide different behavior. |
| 2125 | OMPClause *RebuildOMPUsesAllocatorsClause( |
| 2126 | ArrayRef<Sema::UsesAllocatorsData> Data, SourceLocation StartLoc, |
| 2127 | SourceLocation LParenLoc, SourceLocation EndLoc) { |
| 2128 | return getSema().ActOnOpenMPUsesAllocatorClause(StartLoc, LParenLoc, EndLoc, |
| 2129 | Data); |
| 2130 | } |
| 2131 | |
| 2132 | /// Build a new OpenMP 'affinity' clause. |
| 2133 | /// |
| 2134 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2135 | /// Subclasses may override this routine to provide different behavior. |
| 2136 | OMPClause *RebuildOMPAffinityClause(SourceLocation StartLoc, |
| 2137 | SourceLocation LParenLoc, |
| 2138 | SourceLocation ColonLoc, |
| 2139 | SourceLocation EndLoc, Expr *Modifier, |
| 2140 | ArrayRef<Expr *> Locators) { |
| 2141 | return getSema().ActOnOpenMPAffinityClause(StartLoc, LParenLoc, ColonLoc, |
| 2142 | EndLoc, Modifier, Locators); |
| 2143 | } |
| 2144 | |
| 2145 | /// Build a new OpenMP 'order' clause. |
| 2146 | /// |
| 2147 | /// By default, performs semantic analysis to build the new OpenMP clause. |
| 2148 | /// Subclasses may override this routine to provide different behavior. |
| 2149 | OMPClause *RebuildOMPOrderClause(OpenMPOrderClauseKind Kind, |
| 2150 | SourceLocation KindKwLoc, |
| 2151 | SourceLocation StartLoc, |
| 2152 | SourceLocation LParenLoc, |
| 2153 | SourceLocation EndLoc) { |
| 2154 | return getSema().ActOnOpenMPOrderClause(Kind, KindKwLoc, StartLoc, |
| 2155 | LParenLoc, EndLoc); |
| 2156 | } |
| 2157 | |
| 2158 | /// Rebuild the operand to an Objective-C \@synchronized statement. |
| 2159 | /// |
| 2160 | /// By default, performs semantic analysis to build the new statement. |
| 2161 | /// Subclasses may override this routine to provide different behavior. |
| 2162 | ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, |
| 2163 | Expr *object) { |
| 2164 | return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); |
| 2165 | } |
| 2166 | |
| 2167 | /// Build a new Objective-C \@synchronized statement. |
| 2168 | /// |
| 2169 | /// By default, performs semantic analysis to build the new statement. |
| 2170 | /// Subclasses may override this routine to provide different behavior. |
| 2171 | StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, |
| 2172 | Expr *Object, Stmt *Body) { |
| 2173 | return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); |
| 2174 | } |
| 2175 | |
| 2176 | /// Build a new Objective-C \@autoreleasepool statement. |
| 2177 | /// |
| 2178 | /// By default, performs semantic analysis to build the new statement. |
| 2179 | /// Subclasses may override this routine to provide different behavior. |
| 2180 | StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, |
| 2181 | Stmt *Body) { |
| 2182 | return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); |
| 2183 | } |
| 2184 | |
| 2185 | /// Build a new Objective-C fast enumeration statement. |
| 2186 | /// |
| 2187 | /// By default, performs semantic analysis to build the new statement. |
| 2188 | /// Subclasses may override this routine to provide different behavior. |
| 2189 | StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, |
| 2190 | Stmt *Element, |
| 2191 | Expr *Collection, |
| 2192 | SourceLocation RParenLoc, |
| 2193 | Stmt *Body) { |
| 2194 | StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, |
| 2195 | Element, |
| 2196 | Collection, |
| 2197 | RParenLoc); |
| 2198 | if (ForEachStmt.isInvalid()) |
| 2199 | return StmtError(); |
| 2200 | |
| 2201 | return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body); |
| 2202 | } |
| 2203 | |
| 2204 | /// Build a new C++ exception declaration. |
| 2205 | /// |
| 2206 | /// By default, performs semantic analysis to build the new decaration. |
| 2207 | /// Subclasses may override this routine to provide different behavior. |
| 2208 | VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, |
| 2209 | TypeSourceInfo *Declarator, |
| 2210 | SourceLocation StartLoc, |
| 2211 | SourceLocation IdLoc, |
| 2212 | IdentifierInfo *Id) { |
| 2213 | VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator, |
| 2214 | StartLoc, IdLoc, Id); |
| 2215 | if (Var) |
| 2216 | getSema().CurContext->addDecl(Var); |
| 2217 | return Var; |
| 2218 | } |
| 2219 | |
| 2220 | /// Build a new C++ catch statement. |
| 2221 | /// |
| 2222 | /// By default, performs semantic analysis to build the new statement. |
| 2223 | /// Subclasses may override this routine to provide different behavior. |
| 2224 | StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, |
| 2225 | VarDecl *ExceptionDecl, |
| 2226 | Stmt *Handler) { |
| 2227 | return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, |
| 2228 | Handler)); |
| 2229 | } |
| 2230 | |
| 2231 | /// Build a new C++ try statement. |
| 2232 | /// |
| 2233 | /// By default, performs semantic analysis to build the new statement. |
| 2234 | /// Subclasses may override this routine to provide different behavior. |
| 2235 | StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock, |
| 2236 | ArrayRef<Stmt *> Handlers) { |
| 2237 | return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); |
| 2238 | } |
| 2239 | |
| 2240 | /// Build a new C++0x range-based for statement. |
| 2241 | /// |
| 2242 | /// By default, performs semantic analysis to build the new statement. |
| 2243 | /// Subclasses may override this routine to provide different behavior. |
| 2244 | StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, |
| 2245 | SourceLocation CoawaitLoc, Stmt *Init, |
| 2246 | SourceLocation ColonLoc, Stmt *Range, |
| 2247 | Stmt *Begin, Stmt *End, Expr *Cond, |
| 2248 | Expr *Inc, Stmt *LoopVar, |
| 2249 | SourceLocation RParenLoc) { |
| 2250 | // If we've just learned that the range is actually an Objective-C |
| 2251 | // collection, treat this as an Objective-C fast enumeration loop. |
| 2252 | if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) { |
| 2253 | if (RangeStmt->isSingleDecl()) { |
| 2254 | if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) { |
| 2255 | if (RangeVar->isInvalidDecl()) |
| 2256 | return StmtError(); |
| 2257 | |
| 2258 | Expr *RangeExpr = RangeVar->getInit(); |
| 2259 | if (!RangeExpr->isTypeDependent() && |
| 2260 | RangeExpr->getType()->isObjCObjectPointerType()) { |
| 2261 | // FIXME: Support init-statements in Objective-C++20 ranged for |
| 2262 | // statement. |
| 2263 | if (Init) { |
| 2264 | return SemaRef.Diag(Init->getBeginLoc(), |
| 2265 | diag::err_objc_for_range_init_stmt) |
| 2266 | << Init->getSourceRange(); |
| 2267 | } |
| 2268 | return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, |
| 2269 | RangeExpr, RParenLoc); |
| 2270 | } |
| 2271 | } |
| 2272 | } |
| 2273 | } |
| 2274 | |
| 2275 | return getSema().BuildCXXForRangeStmt(ForLoc, CoawaitLoc, Init, ColonLoc, |
| 2276 | Range, Begin, End, Cond, Inc, LoopVar, |
| 2277 | RParenLoc, Sema::BFRK_Rebuild); |
| 2278 | } |
| 2279 | |
| 2280 | /// Build a new C++0x range-based for statement. |
| 2281 | /// |
| 2282 | /// By default, performs semantic analysis to build the new statement. |
| 2283 | /// Subclasses may override this routine to provide different behavior. |
| 2284 | StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, |
| 2285 | bool IsIfExists, |
| 2286 | NestedNameSpecifierLoc QualifierLoc, |
| 2287 | DeclarationNameInfo NameInfo, |
| 2288 | Stmt *Nested) { |
| 2289 | return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, |
| 2290 | QualifierLoc, NameInfo, Nested); |
| 2291 | } |
| 2292 | |
| 2293 | /// Attach body to a C++0x range-based for statement. |
| 2294 | /// |
| 2295 | /// By default, performs semantic analysis to finish the new statement. |
| 2296 | /// Subclasses may override this routine to provide different behavior. |
| 2297 | StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { |
| 2298 | return getSema().FinishCXXForRangeStmt(ForRange, Body); |
| 2299 | } |
| 2300 | |
| 2301 | StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc, |
| 2302 | Stmt *TryBlock, Stmt *Handler) { |
| 2303 | return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler); |
| 2304 | } |
| 2305 | |
| 2306 | StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr, |
| 2307 | Stmt *Block) { |
| 2308 | return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block); |
| 2309 | } |
| 2310 | |
| 2311 | StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) { |
| 2312 | return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block); |
| 2313 | } |
| 2314 | |
| 2315 | /// Build a new predefined expression. |
| 2316 | /// |
| 2317 | /// By default, performs semantic analysis to build the new expression. |
| 2318 | /// Subclasses may override this routine to provide different behavior. |
| 2319 | ExprResult RebuildPredefinedExpr(SourceLocation Loc, |
| 2320 | PredefinedExpr::IdentKind IK) { |
| 2321 | return getSema().BuildPredefinedExpr(Loc, IK); |
| 2322 | } |
| 2323 | |
| 2324 | /// Build a new expression that references a declaration. |
| 2325 | /// |
| 2326 | /// By default, performs semantic analysis to build the new expression. |
| 2327 | /// Subclasses may override this routine to provide different behavior. |
| 2328 | ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, |
| 2329 | LookupResult &R, |
| 2330 | bool RequiresADL) { |
| 2331 | return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); |
| 2332 | } |
| 2333 | |
| 2334 | |
| 2335 | /// Build a new expression that references a declaration. |
| 2336 | /// |
| 2337 | /// By default, performs semantic analysis to build the new expression. |
| 2338 | /// Subclasses may override this routine to provide different behavior. |
| 2339 | ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, |
| 2340 | ValueDecl *VD, |
| 2341 | const DeclarationNameInfo &NameInfo, |
| 2342 | NamedDecl *Found, |
| 2343 | TemplateArgumentListInfo *TemplateArgs) { |
| 2344 | CXXScopeSpec SS; |
| 2345 | SS.Adopt(QualifierLoc); |
| 2346 | return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD, Found, |
| 2347 | TemplateArgs); |
| 2348 | } |
| 2349 | |
| 2350 | /// Build a new expression in parentheses. |
| 2351 | /// |
| 2352 | /// By default, performs semantic analysis to build the new expression. |
| 2353 | /// Subclasses may override this routine to provide different behavior. |
| 2354 | ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, |
| 2355 | SourceLocation RParen) { |
| 2356 | return getSema().ActOnParenExpr(LParen, RParen, SubExpr); |
| 2357 | } |
| 2358 | |
| 2359 | /// Build a new pseudo-destructor expression. |
| 2360 | /// |
| 2361 | /// By default, performs semantic analysis to build the new expression. |
| 2362 | /// Subclasses may override this routine to provide different behavior. |
| 2363 | ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, |
| 2364 | SourceLocation OperatorLoc, |
| 2365 | bool isArrow, |
| 2366 | CXXScopeSpec &SS, |
| 2367 | TypeSourceInfo *ScopeType, |
| 2368 | SourceLocation CCLoc, |
| 2369 | SourceLocation TildeLoc, |
| 2370 | PseudoDestructorTypeStorage Destroyed); |
| 2371 | |
| 2372 | /// Build a new unary operator expression. |
| 2373 | /// |
| 2374 | /// By default, performs semantic analysis to build the new expression. |
| 2375 | /// Subclasses may override this routine to provide different behavior. |
| 2376 | ExprResult RebuildUnaryOperator(SourceLocation OpLoc, |
| 2377 | UnaryOperatorKind Opc, |
| 2378 | Expr *SubExpr) { |
| 2379 | return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr); |
| 2380 | } |
| 2381 | |
| 2382 | /// Build a new builtin offsetof expression. |
| 2383 | /// |
| 2384 | /// By default, performs semantic analysis to build the new expression. |
| 2385 | /// Subclasses may override this routine to provide different behavior. |
| 2386 | ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, |
| 2387 | TypeSourceInfo *Type, |
| 2388 | ArrayRef<Sema::OffsetOfComponent> Components, |
| 2389 | SourceLocation RParenLoc) { |
| 2390 | return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, |
| 2391 | RParenLoc); |
| 2392 | } |
| 2393 | |
| 2394 | /// Build a new sizeof, alignof or vec_step expression with a |
| 2395 | /// type argument. |
| 2396 | /// |
| 2397 | /// By default, performs semantic analysis to build the new expression. |
| 2398 | /// Subclasses may override this routine to provide different behavior. |
| 2399 | ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, |
| 2400 | SourceLocation OpLoc, |
| 2401 | UnaryExprOrTypeTrait ExprKind, |
| 2402 | SourceRange R) { |
| 2403 | return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); |
| 2404 | } |
| 2405 | |
| 2406 | /// Build a new sizeof, alignof or vec step expression with an |
| 2407 | /// expression argument. |
| 2408 | /// |
| 2409 | /// By default, performs semantic analysis to build the new expression. |
| 2410 | /// Subclasses may override this routine to provide different behavior. |
| 2411 | ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, |
| 2412 | UnaryExprOrTypeTrait ExprKind, |
| 2413 | SourceRange R) { |
| 2414 | ExprResult Result |
| 2415 | = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); |
| 2416 | if (Result.isInvalid()) |
| 2417 | return ExprError(); |
| 2418 | |
| 2419 | return Result; |
| 2420 | } |
| 2421 | |
| 2422 | /// Build a new array subscript expression. |
| 2423 | /// |
| 2424 | /// By default, performs semantic analysis to build the new expression. |
| 2425 | /// Subclasses may override this routine to provide different behavior. |
| 2426 | ExprResult RebuildArraySubscriptExpr(Expr *LHS, |
| 2427 | SourceLocation LBracketLoc, |
| 2428 | Expr *RHS, |
| 2429 | SourceLocation RBracketLoc) { |
| 2430 | return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS, |
| 2431 | LBracketLoc, RHS, |
| 2432 | RBracketLoc); |
| 2433 | } |
| 2434 | |
| 2435 | /// Build a new matrix subscript expression. |
| 2436 | /// |
| 2437 | /// By default, performs semantic analysis to build the new expression. |
| 2438 | /// Subclasses may override this routine to provide different behavior. |
| 2439 | ExprResult RebuildMatrixSubscriptExpr(Expr *Base, Expr *RowIdx, |
| 2440 | Expr *ColumnIdx, |
| 2441 | SourceLocation RBracketLoc) { |
| 2442 | return getSema().CreateBuiltinMatrixSubscriptExpr(Base, RowIdx, ColumnIdx, |
| 2443 | RBracketLoc); |
| 2444 | } |
| 2445 | |
| 2446 | /// Build a new array section expression. |
| 2447 | /// |
| 2448 | /// By default, performs semantic analysis to build the new expression. |
| 2449 | /// Subclasses may override this routine to provide different behavior. |
| 2450 | ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc, |
| 2451 | Expr *LowerBound, |
| 2452 | SourceLocation ColonLocFirst, |
| 2453 | SourceLocation ColonLocSecond, |
| 2454 | Expr *Length, Expr *Stride, |
| 2455 | SourceLocation RBracketLoc) { |
| 2456 | return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound, |
| 2457 | ColonLocFirst, ColonLocSecond, |
| 2458 | Length, Stride, RBracketLoc); |
| 2459 | } |
| 2460 | |
| 2461 | /// Build a new array shaping expression. |
| 2462 | /// |
| 2463 | /// By default, performs semantic analysis to build the new expression. |
| 2464 | /// Subclasses may override this routine to provide different behavior. |
| 2465 | ExprResult RebuildOMPArrayShapingExpr(Expr *Base, SourceLocation LParenLoc, |
| 2466 | SourceLocation RParenLoc, |
| 2467 | ArrayRef<Expr *> Dims, |
| 2468 | ArrayRef<SourceRange> BracketsRanges) { |
| 2469 | return getSema().ActOnOMPArrayShapingExpr(Base, LParenLoc, RParenLoc, Dims, |
| 2470 | BracketsRanges); |
| 2471 | } |
| 2472 | |
| 2473 | /// Build a new iterator expression. |
| 2474 | /// |
| 2475 | /// By default, performs semantic analysis to build the new expression. |
| 2476 | /// Subclasses may override this routine to provide different behavior. |
| 2477 | ExprResult RebuildOMPIteratorExpr( |
| 2478 | SourceLocation IteratorKwLoc, SourceLocation LLoc, SourceLocation RLoc, |
| 2479 | ArrayRef<Sema::OMPIteratorData> Data) { |
| 2480 | return getSema().ActOnOMPIteratorExpr(/*Scope=*/nullptr, IteratorKwLoc, |
| 2481 | LLoc, RLoc, Data); |
| 2482 | } |
| 2483 | |
| 2484 | /// Build a new call expression. |
| 2485 | /// |
| 2486 | /// By default, performs semantic analysis to build the new expression. |
| 2487 | /// Subclasses may override this routine to provide different behavior. |
| 2488 | ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, |
| 2489 | MultiExprArg Args, |
| 2490 | SourceLocation RParenLoc, |
| 2491 | Expr *ExecConfig = nullptr) { |
| 2492 | return getSema().ActOnCallExpr( |
| 2493 | /*Scope=*/nullptr, Callee, LParenLoc, Args, RParenLoc, ExecConfig); |
| 2494 | } |
| 2495 | |
| 2496 | /// Build a new member access expression. |
| 2497 | /// |
| 2498 | /// By default, performs semantic analysis to build the new expression. |
| 2499 | /// Subclasses may override this routine to provide different behavior. |
| 2500 | ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, |
| 2501 | bool isArrow, |
| 2502 | NestedNameSpecifierLoc QualifierLoc, |
| 2503 | SourceLocation TemplateKWLoc, |
| 2504 | const DeclarationNameInfo &MemberNameInfo, |
| 2505 | ValueDecl *Member, |
| 2506 | NamedDecl *FoundDecl, |
| 2507 | const TemplateArgumentListInfo *ExplicitTemplateArgs, |
| 2508 | NamedDecl *FirstQualifierInScope) { |
| 2509 | ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, |
| 2510 | isArrow); |
| 2511 | if (!Member->getDeclName()) { |
| 2512 | // We have a reference to an unnamed field. This is always the |
| 2513 | // base of an anonymous struct/union member access, i.e. the |
| 2514 | // field is always of record type. |
| 2515 | assert(Member->getType()->isRecordType() && |
| 2516 | "unnamed member not of record type?" ); |
| 2517 | |
| 2518 | BaseResult = |
| 2519 | getSema().PerformObjectMemberConversion(BaseResult.get(), |
| 2520 | QualifierLoc.getNestedNameSpecifier(), |
| 2521 | FoundDecl, Member); |
| 2522 | if (BaseResult.isInvalid()) |
| 2523 | return ExprError(); |
| 2524 | Base = BaseResult.get(); |
| 2525 | |
| 2526 | CXXScopeSpec EmptySS; |
| 2527 | return getSema().BuildFieldReferenceExpr( |
| 2528 | Base, isArrow, OpLoc, EmptySS, cast<FieldDecl>(Member), |
| 2529 | DeclAccessPair::make(FoundDecl, FoundDecl->getAccess()), MemberNameInfo); |
| 2530 | } |
| 2531 | |
| 2532 | CXXScopeSpec SS; |
| 2533 | SS.Adopt(QualifierLoc); |
| 2534 | |
| 2535 | Base = BaseResult.get(); |
| 2536 | QualType BaseType = Base->getType(); |
| 2537 | |
| 2538 | if (isArrow && !BaseType->isPointerType()) |
| 2539 | return ExprError(); |
| 2540 | |
| 2541 | // FIXME: this involves duplicating earlier analysis in a lot of |
| 2542 | // cases; we should avoid this when possible. |
| 2543 | LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); |
| 2544 | R.addDecl(FoundDecl); |
| 2545 | R.resolveKind(); |
| 2546 | |
| 2547 | return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, |
| 2548 | SS, TemplateKWLoc, |
| 2549 | FirstQualifierInScope, |
| 2550 | R, ExplicitTemplateArgs, |
| 2551 | /*S*/nullptr); |
| 2552 | } |
| 2553 | |
| 2554 | /// Build a new binary operator expression. |
| 2555 | /// |
| 2556 | /// By default, performs semantic analysis to build the new expression. |
| 2557 | /// Subclasses may override this routine to provide different behavior. |
| 2558 | ExprResult RebuildBinaryOperator(SourceLocation OpLoc, |
| 2559 | BinaryOperatorKind Opc, |
| 2560 | Expr *LHS, Expr *RHS) { |
| 2561 | return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS); |
| 2562 | } |
| 2563 | |
| 2564 | /// Build a new rewritten operator expression. |
| 2565 | /// |
| 2566 | /// By default, performs semantic analysis to build the new expression. |
| 2567 | /// Subclasses may override this routine to provide different behavior. |
| 2568 | ExprResult RebuildCXXRewrittenBinaryOperator( |
| 2569 | SourceLocation OpLoc, BinaryOperatorKind Opcode, |
| 2570 | const UnresolvedSetImpl &UnqualLookups, Expr *LHS, Expr *RHS) { |
| 2571 | return getSema().CreateOverloadedBinOp(OpLoc, Opcode, UnqualLookups, LHS, |
| 2572 | RHS, /*RequiresADL*/false); |
| 2573 | } |
| 2574 | |
| 2575 | /// Build a new conditional operator expression. |
| 2576 | /// |
| 2577 | /// By default, performs semantic analysis to build the new expression. |
| 2578 | /// Subclasses may override this routine to provide different behavior. |
| 2579 | ExprResult RebuildConditionalOperator(Expr *Cond, |
| 2580 | SourceLocation QuestionLoc, |
| 2581 | Expr *LHS, |
| 2582 | SourceLocation ColonLoc, |
| 2583 | Expr *RHS) { |
| 2584 | return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, |
| 2585 | LHS, RHS); |
| 2586 | } |
| 2587 | |
| 2588 | /// Build a new C-style cast expression. |
| 2589 | /// |
| 2590 | /// By default, performs semantic analysis to build the new expression. |
| 2591 | /// Subclasses may override this routine to provide different behavior. |
| 2592 | ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, |
| 2593 | TypeSourceInfo *TInfo, |
| 2594 | SourceLocation RParenLoc, |
| 2595 | Expr *SubExpr) { |
| 2596 | return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, |
| 2597 | SubExpr); |
| 2598 | } |
| 2599 | |
| 2600 | /// Build a new compound literal expression. |
| 2601 | /// |
| 2602 | /// By default, performs semantic analysis to build the new expression. |
| 2603 | /// Subclasses may override this routine to provide different behavior. |
| 2604 | ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, |
| 2605 | TypeSourceInfo *TInfo, |
| 2606 | SourceLocation RParenLoc, |
| 2607 | Expr *Init) { |
| 2608 | return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, |
| 2609 | Init); |
| 2610 | } |
| 2611 | |
| 2612 | /// Build a new extended vector element access expression. |
| 2613 | /// |
| 2614 | /// By default, performs semantic analysis to build the new expression. |
| 2615 | /// Subclasses may override this routine to provide different behavior. |
| 2616 | ExprResult RebuildExtVectorElementExpr(Expr *Base, |
| 2617 | SourceLocation OpLoc, |
| 2618 | SourceLocation AccessorLoc, |
| 2619 | IdentifierInfo &Accessor) { |
| 2620 | |
| 2621 | CXXScopeSpec SS; |
| 2622 | DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); |
| 2623 | return getSema().BuildMemberReferenceExpr(Base, Base->getType(), |
| 2624 | OpLoc, /*IsArrow*/ false, |
| 2625 | SS, SourceLocation(), |
| 2626 | /*FirstQualifierInScope*/ nullptr, |
| 2627 | NameInfo, |
| 2628 | /* TemplateArgs */ nullptr, |
| 2629 | /*S*/ nullptr); |
| 2630 | } |
| 2631 | |
| 2632 | /// Build a new initializer list expression. |
| 2633 | /// |
| 2634 | /// By default, performs semantic analysis to build the new expression. |
| 2635 | /// Subclasses may override this routine to provide different behavior. |
| 2636 | ExprResult RebuildInitList(SourceLocation LBraceLoc, |
| 2637 | MultiExprArg Inits, |
| 2638 | SourceLocation RBraceLoc) { |
| 2639 | return SemaRef.BuildInitList(LBraceLoc, Inits, RBraceLoc); |
| 2640 | } |
| 2641 | |
| 2642 | /// Build a new designated initializer expression. |
| 2643 | /// |
| 2644 | /// By default, performs semantic analysis to build the new expression. |
| 2645 | /// Subclasses may override this routine to provide different behavior. |
| 2646 | ExprResult RebuildDesignatedInitExpr(Designation &Desig, |
| 2647 | MultiExprArg ArrayExprs, |
| 2648 | SourceLocation EqualOrColonLoc, |
| 2649 | bool GNUSyntax, |
| 2650 | Expr *Init) { |
| 2651 | ExprResult Result |
| 2652 | = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, |
| 2653 | Init); |
| 2654 | if (Result.isInvalid()) |
| 2655 | return ExprError(); |
| 2656 | |
| 2657 | return Result; |
| 2658 | } |
| 2659 | |
| 2660 | /// Build a new value-initialized expression. |
| 2661 | /// |
| 2662 | /// By default, builds the implicit value initialization without performing |
| 2663 | /// any semantic analysis. Subclasses may override this routine to provide |
| 2664 | /// different behavior. |
| 2665 | ExprResult RebuildImplicitValueInitExpr(QualType T) { |
| 2666 | return new (SemaRef.Context) ImplicitValueInitExpr(T); |
| 2667 | } |
| 2668 | |
| 2669 | /// Build a new \c va_arg expression. |
| 2670 | /// |
| 2671 | /// By default, performs semantic analysis to build the new expression. |
| 2672 | /// Subclasses may override this routine to provide different behavior. |
| 2673 | ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, |
| 2674 | Expr *SubExpr, TypeSourceInfo *TInfo, |
| 2675 | SourceLocation RParenLoc) { |
| 2676 | return getSema().BuildVAArgExpr(BuiltinLoc, |
| 2677 | SubExpr, TInfo, |
| 2678 | RParenLoc); |
| 2679 | } |
| 2680 | |
| 2681 | /// Build a new expression list in parentheses. |
| 2682 | /// |
| 2683 | /// By default, performs semantic analysis to build the new expression. |
| 2684 | /// Subclasses may override this routine to provide different behavior. |
| 2685 | ExprResult RebuildParenListExpr(SourceLocation LParenLoc, |
| 2686 | MultiExprArg SubExprs, |
| 2687 | SourceLocation RParenLoc) { |
| 2688 | return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); |
| 2689 | } |
| 2690 | |
| 2691 | /// Build a new address-of-label expression. |
| 2692 | /// |
| 2693 | /// By default, performs semantic analysis, using the name of the label |
| 2694 | /// rather than attempting to map the label statement itself. |
| 2695 | /// Subclasses may override this routine to provide different behavior. |
| 2696 | ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, |
| 2697 | SourceLocation LabelLoc, LabelDecl *Label) { |
| 2698 | return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); |
| 2699 | } |
| 2700 | |
| 2701 | /// Build a new GNU statement expression. |
| 2702 | /// |
| 2703 | /// By default, performs semantic analysis to build the new expression. |
| 2704 | /// Subclasses may override this routine to provide different behavior. |
| 2705 | ExprResult RebuildStmtExpr(SourceLocation LParenLoc, Stmt *SubStmt, |
| 2706 | SourceLocation RParenLoc, unsigned TemplateDepth) { |
| 2707 | return getSema().BuildStmtExpr(LParenLoc, SubStmt, RParenLoc, |
| 2708 | TemplateDepth); |
| 2709 | } |
| 2710 | |
| 2711 | /// Build a new __builtin_choose_expr expression. |
| 2712 | /// |
| 2713 | /// By default, performs semantic analysis to build the new expression. |
| 2714 | /// Subclasses may override this routine to provide different behavior. |
| 2715 | ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, |
| 2716 | Expr *Cond, Expr *LHS, Expr *RHS, |
| 2717 | SourceLocation RParenLoc) { |
| 2718 | return SemaRef.ActOnChooseExpr(BuiltinLoc, |
| 2719 | Cond, LHS, RHS, |
| 2720 | RParenLoc); |
| 2721 | } |
| 2722 | |
| 2723 | /// Build a new generic selection expression. |
| 2724 | /// |
| 2725 | /// By default, performs semantic analysis to build the new expression. |
| 2726 | /// Subclasses may override this routine to provide different behavior. |
| 2727 | ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, |
| 2728 | SourceLocation DefaultLoc, |
| 2729 | SourceLocation RParenLoc, |
| 2730 | Expr *ControllingExpr, |
| 2731 | ArrayRef<TypeSourceInfo *> Types, |
| 2732 | ArrayRef<Expr *> Exprs) { |
| 2733 | return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, |
| 2734 | ControllingExpr, Types, Exprs); |
| 2735 | } |
| 2736 | |
| 2737 | /// Build a new overloaded operator call expression. |
| 2738 | /// |
| 2739 | /// By default, performs semantic analysis to build the new expression. |
| 2740 | /// The semantic analysis provides the behavior of template instantiation, |
| 2741 | /// copying with transformations that turn what looks like an overloaded |
| 2742 | /// operator call into a use of a builtin operator, performing |
| 2743 | /// argument-dependent lookup, etc. Subclasses may override this routine to |
| 2744 | /// provide different behavior. |
| 2745 | ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 2746 | SourceLocation OpLoc, |
| 2747 | Expr *Callee, |
| 2748 | Expr *First, |
| 2749 | Expr *Second); |
| 2750 | |
| 2751 | /// Build a new C++ "named" cast expression, such as static_cast or |
| 2752 | /// reinterpret_cast. |
| 2753 | /// |
| 2754 | /// By default, this routine dispatches to one of the more-specific routines |
| 2755 | /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). |
| 2756 | /// Subclasses may override this routine to provide different behavior. |
| 2757 | ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, |
| 2758 | Stmt::StmtClass Class, |
| 2759 | SourceLocation LAngleLoc, |
| 2760 | TypeSourceInfo *TInfo, |
| 2761 | SourceLocation RAngleLoc, |
| 2762 | SourceLocation LParenLoc, |
| 2763 | Expr *SubExpr, |
| 2764 | SourceLocation RParenLoc) { |
| 2765 | switch (Class) { |
| 2766 | case Stmt::CXXStaticCastExprClass: |
| 2767 | return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, |
| 2768 | RAngleLoc, LParenLoc, |
| 2769 | SubExpr, RParenLoc); |
| 2770 | |
| 2771 | case Stmt::CXXDynamicCastExprClass: |
| 2772 | return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, |
| 2773 | RAngleLoc, LParenLoc, |
| 2774 | SubExpr, RParenLoc); |
| 2775 | |
| 2776 | case Stmt::CXXReinterpretCastExprClass: |
| 2777 | return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, |
| 2778 | RAngleLoc, LParenLoc, |
| 2779 | SubExpr, |
| 2780 | RParenLoc); |
| 2781 | |
| 2782 | case Stmt::CXXConstCastExprClass: |
| 2783 | return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, |
| 2784 | RAngleLoc, LParenLoc, |
| 2785 | SubExpr, RParenLoc); |
| 2786 | |
| 2787 | case Stmt::CXXAddrspaceCastExprClass: |
| 2788 | return getDerived().RebuildCXXAddrspaceCastExpr( |
| 2789 | OpLoc, LAngleLoc, TInfo, RAngleLoc, LParenLoc, SubExpr, RParenLoc); |
| 2790 | |
| 2791 | default: |
| 2792 | llvm_unreachable("Invalid C++ named cast" ); |
| 2793 | } |
| 2794 | } |
| 2795 | |
| 2796 | /// Build a new C++ static_cast expression. |
| 2797 | /// |
| 2798 | /// By default, performs semantic analysis to build the new expression. |
| 2799 | /// Subclasses may override this routine to provide different behavior. |
| 2800 | ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, |
| 2801 | SourceLocation LAngleLoc, |
| 2802 | TypeSourceInfo *TInfo, |
| 2803 | SourceLocation RAngleLoc, |
| 2804 | SourceLocation LParenLoc, |
| 2805 | Expr *SubExpr, |
| 2806 | SourceLocation RParenLoc) { |
| 2807 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, |
| 2808 | TInfo, SubExpr, |
| 2809 | SourceRange(LAngleLoc, RAngleLoc), |
| 2810 | SourceRange(LParenLoc, RParenLoc)); |
| 2811 | } |
| 2812 | |
| 2813 | /// Build a new C++ dynamic_cast expression. |
| 2814 | /// |
| 2815 | /// By default, performs semantic analysis to build the new expression. |
| 2816 | /// Subclasses may override this routine to provide different behavior. |
| 2817 | ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, |
| 2818 | SourceLocation LAngleLoc, |
| 2819 | TypeSourceInfo *TInfo, |
| 2820 | SourceLocation RAngleLoc, |
| 2821 | SourceLocation LParenLoc, |
| 2822 | Expr *SubExpr, |
| 2823 | SourceLocation RParenLoc) { |
| 2824 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, |
| 2825 | TInfo, SubExpr, |
| 2826 | SourceRange(LAngleLoc, RAngleLoc), |
| 2827 | SourceRange(LParenLoc, RParenLoc)); |
| 2828 | } |
| 2829 | |
| 2830 | /// Build a new C++ reinterpret_cast expression. |
| 2831 | /// |
| 2832 | /// By default, performs semantic analysis to build the new expression. |
| 2833 | /// Subclasses may override this routine to provide different behavior. |
| 2834 | ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, |
| 2835 | SourceLocation LAngleLoc, |
| 2836 | TypeSourceInfo *TInfo, |
| 2837 | SourceLocation RAngleLoc, |
| 2838 | SourceLocation LParenLoc, |
| 2839 | Expr *SubExpr, |
| 2840 | SourceLocation RParenLoc) { |
| 2841 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, |
| 2842 | TInfo, SubExpr, |
| 2843 | SourceRange(LAngleLoc, RAngleLoc), |
| 2844 | SourceRange(LParenLoc, RParenLoc)); |
| 2845 | } |
| 2846 | |
| 2847 | /// Build a new C++ const_cast expression. |
| 2848 | /// |
| 2849 | /// By default, performs semantic analysis to build the new expression. |
| 2850 | /// Subclasses may override this routine to provide different behavior. |
| 2851 | ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, |
| 2852 | SourceLocation LAngleLoc, |
| 2853 | TypeSourceInfo *TInfo, |
| 2854 | SourceLocation RAngleLoc, |
| 2855 | SourceLocation LParenLoc, |
| 2856 | Expr *SubExpr, |
| 2857 | SourceLocation RParenLoc) { |
| 2858 | return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, |
| 2859 | TInfo, SubExpr, |
| 2860 | SourceRange(LAngleLoc, RAngleLoc), |
| 2861 | SourceRange(LParenLoc, RParenLoc)); |
| 2862 | } |
| 2863 | |
| 2864 | ExprResult |
| 2865 | RebuildCXXAddrspaceCastExpr(SourceLocation OpLoc, SourceLocation LAngleLoc, |
| 2866 | TypeSourceInfo *TInfo, SourceLocation RAngleLoc, |
| 2867 | SourceLocation LParenLoc, Expr *SubExpr, |
| 2868 | SourceLocation RParenLoc) { |
| 2869 | return getSema().BuildCXXNamedCast( |
| 2870 | OpLoc, tok::kw_addrspace_cast, TInfo, SubExpr, |
| 2871 | SourceRange(LAngleLoc, RAngleLoc), SourceRange(LParenLoc, RParenLoc)); |
| 2872 | } |
| 2873 | |
| 2874 | /// Build a new C++ functional-style cast expression. |
| 2875 | /// |
| 2876 | /// By default, performs semantic analysis to build the new expression. |
| 2877 | /// Subclasses may override this routine to provide different behavior. |
| 2878 | ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, |
| 2879 | SourceLocation LParenLoc, |
| 2880 | Expr *Sub, |
| 2881 | SourceLocation RParenLoc, |
| 2882 | bool ListInitialization) { |
| 2883 | return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, |
| 2884 | MultiExprArg(&Sub, 1), RParenLoc, |
| 2885 | ListInitialization); |
| 2886 | } |
| 2887 | |
| 2888 | /// Build a new C++ __builtin_bit_cast expression. |
| 2889 | /// |
| 2890 | /// By default, performs semantic analysis to build the new expression. |
| 2891 | /// Subclasses may override this routine to provide different behavior. |
| 2892 | ExprResult RebuildBuiltinBitCastExpr(SourceLocation KWLoc, |
| 2893 | TypeSourceInfo *TSI, Expr *Sub, |
| 2894 | SourceLocation RParenLoc) { |
| 2895 | return getSema().BuildBuiltinBitCastExpr(KWLoc, TSI, Sub, RParenLoc); |
| 2896 | } |
| 2897 | |
| 2898 | /// Build a new C++ typeid(type) expression. |
| 2899 | /// |
| 2900 | /// By default, performs semantic analysis to build the new expression. |
| 2901 | /// Subclasses may override this routine to provide different behavior. |
| 2902 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 2903 | SourceLocation TypeidLoc, |
| 2904 | TypeSourceInfo *Operand, |
| 2905 | SourceLocation RParenLoc) { |
| 2906 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| 2907 | RParenLoc); |
| 2908 | } |
| 2909 | |
| 2910 | |
| 2911 | /// Build a new C++ typeid(expr) expression. |
| 2912 | /// |
| 2913 | /// By default, performs semantic analysis to build the new expression. |
| 2914 | /// Subclasses may override this routine to provide different behavior. |
| 2915 | ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, |
| 2916 | SourceLocation TypeidLoc, |
| 2917 | Expr *Operand, |
| 2918 | SourceLocation RParenLoc) { |
| 2919 | return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, |
| 2920 | RParenLoc); |
| 2921 | } |
| 2922 | |
| 2923 | /// Build a new C++ __uuidof(type) expression. |
| 2924 | /// |
| 2925 | /// By default, performs semantic analysis to build the new expression. |
| 2926 | /// Subclasses may override this routine to provide different behavior. |
| 2927 | ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, |
| 2928 | TypeSourceInfo *Operand, |
| 2929 | SourceLocation RParenLoc) { |
| 2930 | return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc); |
| 2931 | } |
| 2932 | |
| 2933 | /// Build a new C++ __uuidof(expr) expression. |
| 2934 | /// |
| 2935 | /// By default, performs semantic analysis to build the new expression. |
| 2936 | /// Subclasses may override this routine to provide different behavior. |
| 2937 | ExprResult RebuildCXXUuidofExpr(QualType Type, SourceLocation TypeidLoc, |
| 2938 | Expr *Operand, SourceLocation RParenLoc) { |
| 2939 | return getSema().BuildCXXUuidof(Type, TypeidLoc, Operand, RParenLoc); |
| 2940 | } |
| 2941 | |
| 2942 | /// Build a new C++ "this" expression. |
| 2943 | /// |
| 2944 | /// By default, builds a new "this" expression without performing any |
| 2945 | /// semantic analysis. Subclasses may override this routine to provide |
| 2946 | /// different behavior. |
| 2947 | ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, |
| 2948 | QualType ThisType, |
| 2949 | bool isImplicit) { |
| 2950 | return getSema().BuildCXXThisExpr(ThisLoc, ThisType, isImplicit); |
| 2951 | } |
| 2952 | |
| 2953 | /// Build a new C++ throw expression. |
| 2954 | /// |
| 2955 | /// By default, performs semantic analysis to build the new expression. |
| 2956 | /// Subclasses may override this routine to provide different behavior. |
| 2957 | ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, |
| 2958 | bool IsThrownVariableInScope) { |
| 2959 | return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); |
| 2960 | } |
| 2961 | |
| 2962 | /// Build a new C++ default-argument expression. |
| 2963 | /// |
| 2964 | /// By default, builds a new default-argument expression, which does not |
| 2965 | /// require any semantic analysis. Subclasses may override this routine to |
| 2966 | /// provide different behavior. |
| 2967 | ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, ParmVarDecl *Param) { |
| 2968 | return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param, |
| 2969 | getSema().CurContext); |
| 2970 | } |
| 2971 | |
| 2972 | /// Build a new C++11 default-initialization expression. |
| 2973 | /// |
| 2974 | /// By default, builds a new default field initialization expression, which |
| 2975 | /// does not require any semantic analysis. Subclasses may override this |
| 2976 | /// routine to provide different behavior. |
| 2977 | ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc, |
| 2978 | FieldDecl *Field) { |
| 2979 | return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field, |
| 2980 | getSema().CurContext); |
| 2981 | } |
| 2982 | |
| 2983 | /// Build a new C++ zero-initialization expression. |
| 2984 | /// |
| 2985 | /// By default, performs semantic analysis to build the new expression. |
| 2986 | /// Subclasses may override this routine to provide different behavior. |
| 2987 | ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, |
| 2988 | SourceLocation LParenLoc, |
| 2989 | SourceLocation RParenLoc) { |
| 2990 | return getSema().BuildCXXTypeConstructExpr( |
| 2991 | TSInfo, LParenLoc, None, RParenLoc, /*ListInitialization=*/false); |
| 2992 | } |
| 2993 | |
| 2994 | /// Build a new C++ "new" expression. |
| 2995 | /// |
| 2996 | /// By default, performs semantic analysis to build the new expression. |
| 2997 | /// Subclasses may override this routine to provide different behavior. |
| 2998 | ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, |
| 2999 | bool UseGlobal, |
| 3000 | SourceLocation PlacementLParen, |
| 3001 | MultiExprArg PlacementArgs, |
| 3002 | SourceLocation PlacementRParen, |
| 3003 | SourceRange TypeIdParens, |
| 3004 | QualType AllocatedType, |
| 3005 | TypeSourceInfo *AllocatedTypeInfo, |
| 3006 | Optional<Expr *> ArraySize, |
| 3007 | SourceRange DirectInitRange, |
| 3008 | Expr *Initializer) { |
| 3009 | return getSema().BuildCXXNew(StartLoc, UseGlobal, |
| 3010 | PlacementLParen, |
| 3011 | PlacementArgs, |
| 3012 | PlacementRParen, |
| 3013 | TypeIdParens, |
| 3014 | AllocatedType, |
| 3015 | AllocatedTypeInfo, |
| 3016 | ArraySize, |
| 3017 | DirectInitRange, |
| 3018 | Initializer); |
| 3019 | } |
| 3020 | |
| 3021 | /// Build a new C++ "delete" expression. |
| 3022 | /// |
| 3023 | /// By default, performs semantic analysis to build the new expression. |
| 3024 | /// Subclasses may override this routine to provide different behavior. |
| 3025 | ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, |
| 3026 | bool IsGlobalDelete, |
| 3027 | bool IsArrayForm, |
| 3028 | Expr *Operand) { |
| 3029 | return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, |
| 3030 | Operand); |
| 3031 | } |
| 3032 | |
| 3033 | /// Build a new type trait expression. |
| 3034 | /// |
| 3035 | /// By default, performs semantic analysis to build the new expression. |
| 3036 | /// Subclasses may override this routine to provide different behavior. |
| 3037 | ExprResult RebuildTypeTrait(TypeTrait Trait, |
| 3038 | SourceLocation StartLoc, |
| 3039 | ArrayRef<TypeSourceInfo *> Args, |
| 3040 | SourceLocation RParenLoc) { |
| 3041 | return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); |
| 3042 | } |
| 3043 | |
| 3044 | /// Build a new array type trait expression. |
| 3045 | /// |
| 3046 | /// By default, performs semantic analysis to build the new expression. |
| 3047 | /// Subclasses may override this routine to provide different behavior. |
| 3048 | ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, |
| 3049 | SourceLocation StartLoc, |
| 3050 | TypeSourceInfo *TSInfo, |
| 3051 | Expr *DimExpr, |
| 3052 | SourceLocation RParenLoc) { |
| 3053 | return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); |
| 3054 | } |
| 3055 | |
| 3056 | /// Build a new expression trait expression. |
| 3057 | /// |
| 3058 | /// By default, performs semantic analysis to build the new expression. |
| 3059 | /// Subclasses may override this routine to provide different behavior. |
| 3060 | ExprResult RebuildExpressionTrait(ExpressionTrait Trait, |
| 3061 | SourceLocation StartLoc, |
| 3062 | Expr *Queried, |
| 3063 | SourceLocation RParenLoc) { |
| 3064 | return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); |
| 3065 | } |
| 3066 | |
| 3067 | /// Build a new (previously unresolved) declaration reference |
| 3068 | /// expression. |
| 3069 | /// |
| 3070 | /// By default, performs semantic analysis to build the new expression. |
| 3071 | /// Subclasses may override this routine to provide different behavior. |
| 3072 | ExprResult RebuildDependentScopeDeclRefExpr( |
| 3073 | NestedNameSpecifierLoc QualifierLoc, |
| 3074 | SourceLocation TemplateKWLoc, |
| 3075 | const DeclarationNameInfo &NameInfo, |
| 3076 | const TemplateArgumentListInfo *TemplateArgs, |
| 3077 | bool IsAddressOfOperand, |
| 3078 | TypeSourceInfo **RecoveryTSI) { |
| 3079 | CXXScopeSpec SS; |
| 3080 | SS.Adopt(QualifierLoc); |
| 3081 | |
| 3082 | if (TemplateArgs || TemplateKWLoc.isValid()) |
| 3083 | return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo, |
| 3084 | TemplateArgs); |
| 3085 | |
| 3086 | return getSema().BuildQualifiedDeclarationNameExpr( |
| 3087 | SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI); |
| 3088 | } |
| 3089 | |
| 3090 | /// Build a new template-id expression. |
| 3091 | /// |
| 3092 | /// By default, performs semantic analysis to build the new expression. |
| 3093 | /// Subclasses may override this routine to provide different behavior. |
| 3094 | ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, |
| 3095 | SourceLocation TemplateKWLoc, |
| 3096 | LookupResult &R, |
| 3097 | bool RequiresADL, |
| 3098 | const TemplateArgumentListInfo *TemplateArgs) { |
| 3099 | return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, |
| 3100 | TemplateArgs); |
| 3101 | } |
| 3102 | |
| 3103 | /// Build a new object-construction expression. |
| 3104 | /// |
| 3105 | /// By default, performs semantic analysis to build the new expression. |
| 3106 | /// Subclasses may override this routine to provide different behavior. |
| 3107 | ExprResult RebuildCXXConstructExpr(QualType T, |
| 3108 | SourceLocation Loc, |
| 3109 | CXXConstructorDecl *Constructor, |
| 3110 | bool IsElidable, |
| 3111 | MultiExprArg Args, |
| 3112 | bool HadMultipleCandidates, |
| 3113 | bool ListInitialization, |
| 3114 | bool StdInitListInitialization, |
| 3115 | bool RequiresZeroInit, |
| 3116 | CXXConstructExpr::ConstructionKind ConstructKind, |
| 3117 | SourceRange ParenRange) { |
| 3118 | // Reconstruct the constructor we originally found, which might be |
| 3119 | // different if this is a call to an inherited constructor. |
| 3120 | CXXConstructorDecl *FoundCtor = Constructor; |
| 3121 | if (Constructor->isInheritingConstructor()) |
| 3122 | FoundCtor = Constructor->getInheritedConstructor().getConstructor(); |
| 3123 | |
| 3124 | SmallVector<Expr*, 8> ConvertedArgs; |
| 3125 | if (getSema().CompleteConstructorCall(FoundCtor, Args, Loc, ConvertedArgs)) |
| 3126 | return ExprError(); |
| 3127 | |
| 3128 | return getSema().BuildCXXConstructExpr(Loc, T, Constructor, |
| 3129 | IsElidable, |
| 3130 | ConvertedArgs, |
| 3131 | HadMultipleCandidates, |
| 3132 | ListInitialization, |
| 3133 | StdInitListInitialization, |
| 3134 | RequiresZeroInit, ConstructKind, |
| 3135 | ParenRange); |
| 3136 | } |
| 3137 | |
| 3138 | /// Build a new implicit construction via inherited constructor |
| 3139 | /// expression. |
| 3140 | ExprResult RebuildCXXInheritedCtorInitExpr(QualType T, SourceLocation Loc, |
| 3141 | CXXConstructorDecl *Constructor, |
| 3142 | bool ConstructsVBase, |
| 3143 | bool InheritedFromVBase) { |
| 3144 | return new (getSema().Context) CXXInheritedCtorInitExpr( |
| 3145 | Loc, T, Constructor, ConstructsVBase, InheritedFromVBase); |
| 3146 | } |
| 3147 | |
| 3148 | /// Build a new object-construction expression. |
| 3149 | /// |
| 3150 | /// By default, performs semantic analysis to build the new expression. |
| 3151 | /// Subclasses may override this routine to provide different behavior. |
| 3152 | ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, |
| 3153 | SourceLocation LParenOrBraceLoc, |
| 3154 | MultiExprArg Args, |
| 3155 | SourceLocation RParenOrBraceLoc, |
| 3156 | bool ListInitialization) { |
| 3157 | return getSema().BuildCXXTypeConstructExpr( |
| 3158 | TSInfo, LParenOrBraceLoc, Args, RParenOrBraceLoc, ListInitialization); |
| 3159 | } |
| 3160 | |
| 3161 | /// Build a new object-construction expression. |
| 3162 | /// |
| 3163 | /// By default, performs semantic analysis to build the new expression. |
| 3164 | /// Subclasses may override this routine to provide different behavior. |
| 3165 | ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, |
| 3166 | SourceLocation LParenLoc, |
| 3167 | MultiExprArg Args, |
| 3168 | SourceLocation RParenLoc, |
| 3169 | bool ListInitialization) { |
| 3170 | return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, Args, |
| 3171 | RParenLoc, ListInitialization); |
| 3172 | } |
| 3173 | |
| 3174 | /// Build a new member reference expression. |
| 3175 | /// |
| 3176 | /// By default, performs semantic analysis to build the new expression. |
| 3177 | /// Subclasses may override this routine to provide different behavior. |
| 3178 | ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, |
| 3179 | QualType BaseType, |
| 3180 | bool IsArrow, |
| 3181 | SourceLocation OperatorLoc, |
| 3182 | NestedNameSpecifierLoc QualifierLoc, |
| 3183 | SourceLocation TemplateKWLoc, |
| 3184 | NamedDecl *FirstQualifierInScope, |
| 3185 | const DeclarationNameInfo &MemberNameInfo, |
| 3186 | const TemplateArgumentListInfo *TemplateArgs) { |
| 3187 | CXXScopeSpec SS; |
| 3188 | SS.Adopt(QualifierLoc); |
| 3189 | |
| 3190 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
| 3191 | OperatorLoc, IsArrow, |
| 3192 | SS, TemplateKWLoc, |
| 3193 | FirstQualifierInScope, |
| 3194 | MemberNameInfo, |
| 3195 | TemplateArgs, /*S*/nullptr); |
| 3196 | } |
| 3197 | |
| 3198 | /// Build a new member reference expression. |
| 3199 | /// |
| 3200 | /// By default, performs semantic analysis to build the new expression. |
| 3201 | /// Subclasses may override this routine to provide different behavior. |
| 3202 | ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, |
| 3203 | SourceLocation OperatorLoc, |
| 3204 | bool IsArrow, |
| 3205 | NestedNameSpecifierLoc QualifierLoc, |
| 3206 | SourceLocation TemplateKWLoc, |
| 3207 | NamedDecl *FirstQualifierInScope, |
| 3208 | LookupResult &R, |
| 3209 | const TemplateArgumentListInfo *TemplateArgs) { |
| 3210 | CXXScopeSpec SS; |
| 3211 | SS.Adopt(QualifierLoc); |
| 3212 | |
| 3213 | return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, |
| 3214 | OperatorLoc, IsArrow, |
| 3215 | SS, TemplateKWLoc, |
| 3216 | FirstQualifierInScope, |
| 3217 | R, TemplateArgs, /*S*/nullptr); |
| 3218 | } |
| 3219 | |
| 3220 | /// Build a new noexcept expression. |
| 3221 | /// |
| 3222 | /// By default, performs semantic analysis to build the new expression. |
| 3223 | /// Subclasses may override this routine to provide different behavior. |
| 3224 | ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { |
| 3225 | return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); |
| 3226 | } |
| 3227 | |
| 3228 | /// Build a new expression to compute the length of a parameter pack. |
| 3229 | ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, |
| 3230 | NamedDecl *Pack, |
| 3231 | SourceLocation PackLoc, |
| 3232 | SourceLocation RParenLoc, |
| 3233 | Optional<unsigned> Length, |
| 3234 | ArrayRef<TemplateArgument> PartialArgs) { |
| 3235 | return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc, |
| 3236 | RParenLoc, Length, PartialArgs); |
| 3237 | } |
| 3238 | |
| 3239 | /// Build a new expression representing a call to a source location |
| 3240 | /// builtin. |
| 3241 | /// |
| 3242 | /// By default, performs semantic analysis to build the new expression. |
| 3243 | /// Subclasses may override this routine to provide different behavior. |
| 3244 | ExprResult RebuildSourceLocExpr(SourceLocExpr::IdentKind Kind, |
| 3245 | SourceLocation BuiltinLoc, |
| 3246 | SourceLocation RPLoc, |
| 3247 | DeclContext *ParentContext) { |
| 3248 | return getSema().BuildSourceLocExpr(Kind, BuiltinLoc, RPLoc, ParentContext); |
| 3249 | } |
| 3250 | |
| 3251 | /// Build a new Objective-C boxed expression. |
| 3252 | /// |
| 3253 | /// By default, performs semantic analysis to build the new expression. |
| 3254 | /// Subclasses may override this routine to provide different behavior. |
| 3255 | ExprResult RebuildConceptSpecializationExpr(NestedNameSpecifierLoc NNS, |
| 3256 | SourceLocation TemplateKWLoc, DeclarationNameInfo ConceptNameInfo, |
| 3257 | NamedDecl *FoundDecl, ConceptDecl *NamedConcept, |
| 3258 | TemplateArgumentListInfo *TALI) { |
| 3259 | CXXScopeSpec SS; |
| 3260 | SS.Adopt(NNS); |
| 3261 | ExprResult Result = getSema().CheckConceptTemplateId(SS, TemplateKWLoc, |
| 3262 | ConceptNameInfo, |
| 3263 | FoundDecl, |
| 3264 | NamedConcept, TALI); |
| 3265 | if (Result.isInvalid()) |
| 3266 | return ExprError(); |
| 3267 | return Result; |
| 3268 | } |
| 3269 | |
| 3270 | /// \brief Build a new requires expression. |
| 3271 | /// |
| 3272 | /// By default, performs semantic analysis to build the new expression. |
| 3273 | /// Subclasses may override this routine to provide different behavior. |
| 3274 | ExprResult RebuildRequiresExpr(SourceLocation RequiresKWLoc, |
| 3275 | RequiresExprBodyDecl *Body, |
| 3276 | ArrayRef<ParmVarDecl *> LocalParameters, |
| 3277 | ArrayRef<concepts::Requirement *> Requirements, |
| 3278 | SourceLocation ClosingBraceLoc) { |
| 3279 | return RequiresExpr::Create(SemaRef.Context, RequiresKWLoc, Body, |
| 3280 | LocalParameters, Requirements, ClosingBraceLoc); |
| 3281 | } |
| 3282 | |
| 3283 | concepts::TypeRequirement * |
| 3284 | RebuildTypeRequirement( |
| 3285 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag) { |
| 3286 | return SemaRef.BuildTypeRequirement(SubstDiag); |
| 3287 | } |
| 3288 | |
| 3289 | concepts::TypeRequirement *RebuildTypeRequirement(TypeSourceInfo *T) { |
| 3290 | return SemaRef.BuildTypeRequirement(T); |
| 3291 | } |
| 3292 | |
| 3293 | concepts::ExprRequirement * |
| 3294 | RebuildExprRequirement( |
| 3295 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag, bool IsSimple, |
| 3296 | SourceLocation NoexceptLoc, |
| 3297 | concepts::ExprRequirement::ReturnTypeRequirement Ret) { |
| 3298 | return SemaRef.BuildExprRequirement(SubstDiag, IsSimple, NoexceptLoc, |
| 3299 | std::move(Ret)); |
| 3300 | } |
| 3301 | |
| 3302 | concepts::ExprRequirement * |
| 3303 | RebuildExprRequirement(Expr *E, bool IsSimple, SourceLocation NoexceptLoc, |
| 3304 | concepts::ExprRequirement::ReturnTypeRequirement Ret) { |
| 3305 | return SemaRef.BuildExprRequirement(E, IsSimple, NoexceptLoc, |
| 3306 | std::move(Ret)); |
| 3307 | } |
| 3308 | |
| 3309 | concepts::NestedRequirement * |
| 3310 | RebuildNestedRequirement( |
| 3311 | concepts::Requirement::SubstitutionDiagnostic *SubstDiag) { |
| 3312 | return SemaRef.BuildNestedRequirement(SubstDiag); |
| 3313 | } |
| 3314 | |
| 3315 | concepts::NestedRequirement *RebuildNestedRequirement(Expr *Constraint) { |
| 3316 | return SemaRef.BuildNestedRequirement(Constraint); |
| 3317 | } |
| 3318 | |
| 3319 | /// \brief Build a new Objective-C boxed expression. |
| 3320 | /// |
| 3321 | /// By default, performs semantic analysis to build the new expression. |
| 3322 | /// Subclasses may override this routine to provide different behavior. |
| 3323 | ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { |
| 3324 | return getSema().BuildObjCBoxedExpr(SR, ValueExpr); |
| 3325 | } |
| 3326 | |
| 3327 | /// Build a new Objective-C array literal. |
| 3328 | /// |
| 3329 | /// By default, performs semantic analysis to build the new expression. |
| 3330 | /// Subclasses may override this routine to provide different behavior. |
| 3331 | ExprResult RebuildObjCArrayLiteral(SourceRange Range, |
| 3332 | Expr **Elements, unsigned NumElements) { |
| 3333 | return getSema().BuildObjCArrayLiteral(Range, |
| 3334 | MultiExprArg(Elements, NumElements)); |
| 3335 | } |
| 3336 | |
| 3337 | ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, |
| 3338 | Expr *Base, Expr *Key, |
| 3339 | ObjCMethodDecl *getterMethod, |
| 3340 | ObjCMethodDecl *setterMethod) { |
| 3341 | return getSema().BuildObjCSubscriptExpression(RB, Base, Key, |
| 3342 | getterMethod, setterMethod); |
| 3343 | } |
| 3344 | |
| 3345 | /// Build a new Objective-C dictionary literal. |
| 3346 | /// |
| 3347 | /// By default, performs semantic analysis to build the new expression. |
| 3348 | /// Subclasses may override this routine to provide different behavior. |
| 3349 | ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, |
| 3350 | MutableArrayRef<ObjCDictionaryElement> Elements) { |
| 3351 | return getSema().BuildObjCDictionaryLiteral(Range, Elements); |
| 3352 | } |
| 3353 | |
| 3354 | /// Build a new Objective-C \@encode expression. |
| 3355 | /// |
| 3356 | /// By default, performs semantic analysis to build the new expression. |
| 3357 | /// Subclasses may override this routine to provide different behavior. |
| 3358 | ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, |
| 3359 | TypeSourceInfo *EncodeTypeInfo, |
| 3360 | SourceLocation RParenLoc) { |
| 3361 | return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc); |
| 3362 | } |
| 3363 | |
| 3364 | /// Build a new Objective-C class message. |
| 3365 | ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, |
| 3366 | Selector Sel, |
| 3367 | ArrayRef<SourceLocation> SelectorLocs, |
| 3368 | ObjCMethodDecl *Method, |
| 3369 | SourceLocation LBracLoc, |
| 3370 | MultiExprArg Args, |
| 3371 | SourceLocation RBracLoc) { |
| 3372 | return SemaRef.BuildClassMessage(ReceiverTypeInfo, |
| 3373 | ReceiverTypeInfo->getType(), |
| 3374 | /*SuperLoc=*/SourceLocation(), |
| 3375 | Sel, Method, LBracLoc, SelectorLocs, |
| 3376 | RBracLoc, Args); |
| 3377 | } |
| 3378 | |
| 3379 | /// Build a new Objective-C instance message. |
| 3380 | ExprResult RebuildObjCMessageExpr(Expr *Receiver, |
| 3381 | Selector Sel, |
| 3382 | ArrayRef<SourceLocation> SelectorLocs, |
| 3383 | ObjCMethodDecl *Method, |
| 3384 | SourceLocation LBracLoc, |
| 3385 | MultiExprArg Args, |
| 3386 | SourceLocation RBracLoc) { |
| 3387 | return SemaRef.BuildInstanceMessage(Receiver, |
| 3388 | Receiver->getType(), |
| 3389 | /*SuperLoc=*/SourceLocation(), |
| 3390 | Sel, Method, LBracLoc, SelectorLocs, |
| 3391 | RBracLoc, Args); |
| 3392 | } |
| 3393 | |
| 3394 | /// Build a new Objective-C instance/class message to 'super'. |
| 3395 | ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc, |
| 3396 | Selector Sel, |
| 3397 | ArrayRef<SourceLocation> SelectorLocs, |
| 3398 | QualType SuperType, |
| 3399 | ObjCMethodDecl *Method, |
| 3400 | SourceLocation LBracLoc, |
| 3401 | MultiExprArg Args, |
| 3402 | SourceLocation RBracLoc) { |
| 3403 | return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr, |
| 3404 | SuperType, |
| 3405 | SuperLoc, |
| 3406 | Sel, Method, LBracLoc, SelectorLocs, |
| 3407 | RBracLoc, Args) |
| 3408 | : SemaRef.BuildClassMessage(nullptr, |
| 3409 | SuperType, |
| 3410 | SuperLoc, |
| 3411 | Sel, Method, LBracLoc, SelectorLocs, |
| 3412 | RBracLoc, Args); |
| 3413 | |
| 3414 | |
| 3415 | } |
| 3416 | |
| 3417 | /// Build a new Objective-C ivar reference expression. |
| 3418 | /// |
| 3419 | /// By default, performs semantic analysis to build the new expression. |
| 3420 | /// Subclasses may override this routine to provide different behavior. |
| 3421 | ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, |
| 3422 | SourceLocation IvarLoc, |
| 3423 | bool IsArrow, bool IsFreeIvar) { |
| 3424 | CXXScopeSpec SS; |
| 3425 | DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc); |
| 3426 | ExprResult Result = getSema().BuildMemberReferenceExpr( |
| 3427 | BaseArg, BaseArg->getType(), |
| 3428 | /*FIXME:*/ IvarLoc, IsArrow, SS, SourceLocation(), |
| 3429 | /*FirstQualifierInScope=*/nullptr, NameInfo, |
| 3430 | /*TemplateArgs=*/nullptr, |
| 3431 | /*S=*/nullptr); |
| 3432 | if (IsFreeIvar && Result.isUsable()) |
| 3433 | cast<ObjCIvarRefExpr>(Result.get())->setIsFreeIvar(IsFreeIvar); |
| 3434 | return Result; |
| 3435 | } |
| 3436 | |
| 3437 | /// Build a new Objective-C property reference expression. |
| 3438 | /// |
| 3439 | /// By default, performs semantic analysis to build the new expression. |
| 3440 | /// Subclasses may override this routine to provide different behavior. |
| 3441 | ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, |
| 3442 | ObjCPropertyDecl *Property, |
| 3443 | SourceLocation PropertyLoc) { |
| 3444 | CXXScopeSpec SS; |
| 3445 | DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc); |
| 3446 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 3447 | /*FIXME:*/PropertyLoc, |
| 3448 | /*IsArrow=*/false, |
| 3449 | SS, SourceLocation(), |
| 3450 | /*FirstQualifierInScope=*/nullptr, |
| 3451 | NameInfo, |
| 3452 | /*TemplateArgs=*/nullptr, |
| 3453 | /*S=*/nullptr); |
| 3454 | } |
| 3455 | |
| 3456 | /// Build a new Objective-C property reference expression. |
| 3457 | /// |
| 3458 | /// By default, performs semantic analysis to build the new expression. |
| 3459 | /// Subclasses may override this routine to provide different behavior. |
| 3460 | ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, |
| 3461 | ObjCMethodDecl *Getter, |
| 3462 | ObjCMethodDecl *Setter, |
| 3463 | SourceLocation PropertyLoc) { |
| 3464 | // Since these expressions can only be value-dependent, we do not |
| 3465 | // need to perform semantic analysis again. |
| 3466 | return Owned( |
| 3467 | new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, |
| 3468 | VK_LValue, OK_ObjCProperty, |
| 3469 | PropertyLoc, Base)); |
| 3470 | } |
| 3471 | |
| 3472 | /// Build a new Objective-C "isa" expression. |
| 3473 | /// |
| 3474 | /// By default, performs semantic analysis to build the new expression. |
| 3475 | /// Subclasses may override this routine to provide different behavior. |
| 3476 | ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, |
| 3477 | SourceLocation OpLoc, bool IsArrow) { |
| 3478 | CXXScopeSpec SS; |
| 3479 | DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa" ), IsaLoc); |
| 3480 | return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(), |
| 3481 | OpLoc, IsArrow, |
| 3482 | SS, SourceLocation(), |
| 3483 | /*FirstQualifierInScope=*/nullptr, |
| 3484 | NameInfo, |
| 3485 | /*TemplateArgs=*/nullptr, |
| 3486 | /*S=*/nullptr); |
| 3487 | } |
| 3488 | |
| 3489 | /// Build a new shuffle vector expression. |
| 3490 | /// |
| 3491 | /// By default, performs semantic analysis to build the new expression. |
| 3492 | /// Subclasses may override this routine to provide different behavior. |
| 3493 | ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, |
| 3494 | MultiExprArg SubExprs, |
| 3495 | SourceLocation RParenLoc) { |
| 3496 | // Find the declaration for __builtin_shufflevector |
| 3497 | const IdentifierInfo &Name |
| 3498 | = SemaRef.Context.Idents.get("__builtin_shufflevector" ); |
| 3499 | TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); |
| 3500 | DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); |
| 3501 | assert(!Lookup.empty() && "No __builtin_shufflevector?" ); |
| 3502 | |
| 3503 | // Build a reference to the __builtin_shufflevector builtin |
| 3504 | FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front()); |
| 3505 | Expr *Callee = new (SemaRef.Context) |
| 3506 | DeclRefExpr(SemaRef.Context, Builtin, false, |
| 3507 | SemaRef.Context.BuiltinFnTy, VK_RValue, BuiltinLoc); |
| 3508 | QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType()); |
| 3509 | Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy, |
| 3510 | CK_BuiltinFnToFnPtr).get(); |
| 3511 | |
| 3512 | // Build the CallExpr |
| 3513 | ExprResult TheCall = CallExpr::Create( |
| 3514 | SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(), |
| 3515 | Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc, |
| 3516 | FPOptionsOverride()); |
| 3517 | |
| 3518 | // Type-check the __builtin_shufflevector expression. |
| 3519 | return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get())); |
| 3520 | } |
| 3521 | |
| 3522 | /// Build a new convert vector expression. |
| 3523 | ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc, |
| 3524 | Expr *SrcExpr, TypeSourceInfo *DstTInfo, |
| 3525 | SourceLocation RParenLoc) { |
| 3526 | return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo, |
| 3527 | BuiltinLoc, RParenLoc); |
| 3528 | } |
| 3529 | |
| 3530 | /// Build a new template argument pack expansion. |
| 3531 | /// |
| 3532 | /// By default, performs semantic analysis to build a new pack expansion |
| 3533 | /// for a template argument. Subclasses may override this routine to provide |
| 3534 | /// different behavior. |
| 3535 | TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, |
| 3536 | SourceLocation EllipsisLoc, |
| 3537 | Optional<unsigned> NumExpansions) { |
| 3538 | switch (Pattern.getArgument().getKind()) { |
| 3539 | case TemplateArgument::Expression: { |
| 3540 | ExprResult Result |
| 3541 | = getSema().CheckPackExpansion(Pattern.getSourceExpression(), |
| 3542 | EllipsisLoc, NumExpansions); |
| 3543 | if (Result.isInvalid()) |
| 3544 | return TemplateArgumentLoc(); |
| 3545 | |
| 3546 | return TemplateArgumentLoc(Result.get(), Result.get()); |
| 3547 | } |
| 3548 | |
| 3549 | case TemplateArgument::Template: |
| 3550 | return TemplateArgumentLoc( |
| 3551 | SemaRef.Context, |
| 3552 | TemplateArgument(Pattern.getArgument().getAsTemplate(), |
| 3553 | NumExpansions), |
| 3554 | Pattern.getTemplateQualifierLoc(), Pattern.getTemplateNameLoc(), |
| 3555 | EllipsisLoc); |
| 3556 | |
| 3557 | case TemplateArgument::Null: |
| 3558 | case TemplateArgument::Integral: |
| 3559 | case TemplateArgument::Declaration: |
| 3560 | case TemplateArgument::Pack: |
| 3561 | case TemplateArgument::TemplateExpansion: |
| 3562 | case TemplateArgument::NullPtr: |
| 3563 | llvm_unreachable("Pack expansion pattern has no parameter packs" ); |
| 3564 | |
| 3565 | case TemplateArgument::Type: |
| 3566 | if (TypeSourceInfo *Expansion |
| 3567 | = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), |
| 3568 | EllipsisLoc, |
| 3569 | NumExpansions)) |
| 3570 | return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), |
| 3571 | Expansion); |
| 3572 | break; |
| 3573 | } |
| 3574 | |
| 3575 | return TemplateArgumentLoc(); |
| 3576 | } |
| 3577 | |
| 3578 | /// Build a new expression pack expansion. |
| 3579 | /// |
| 3580 | /// By default, performs semantic analysis to build a new pack expansion |
| 3581 | /// for an expression. Subclasses may override this routine to provide |
| 3582 | /// different behavior. |
| 3583 | ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, |
| 3584 | Optional<unsigned> NumExpansions) { |
| 3585 | return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); |
| 3586 | } |
| 3587 | |
| 3588 | /// Build a new C++1z fold-expression. |
| 3589 | /// |
| 3590 | /// By default, performs semantic analysis in order to build a new fold |
| 3591 | /// expression. |
| 3592 | ExprResult RebuildCXXFoldExpr(UnresolvedLookupExpr *ULE, |
| 3593 | SourceLocation LParenLoc, Expr *LHS, |
| 3594 | BinaryOperatorKind Operator, |
| 3595 | SourceLocation EllipsisLoc, Expr *RHS, |
| 3596 | SourceLocation RParenLoc, |
| 3597 | Optional<unsigned> NumExpansions) { |
| 3598 | return getSema().BuildCXXFoldExpr(ULE, LParenLoc, LHS, Operator, |
| 3599 | EllipsisLoc, RHS, RParenLoc, |
| 3600 | NumExpansions); |
| 3601 | } |
| 3602 | |
| 3603 | /// Build an empty C++1z fold-expression with the given operator. |
| 3604 | /// |
| 3605 | /// By default, produces the fallback value for the fold-expression, or |
| 3606 | /// produce an error if there is no fallback value. |
| 3607 | ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc, |
| 3608 | BinaryOperatorKind Operator) { |
| 3609 | return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator); |
| 3610 | } |
| 3611 | |
| 3612 | /// Build a new atomic operation expression. |
| 3613 | /// |
| 3614 | /// By default, performs semantic analysis to build the new expression. |
| 3615 | /// Subclasses may override this routine to provide different behavior. |
| 3616 | ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, MultiExprArg SubExprs, |
| 3617 | AtomicExpr::AtomicOp Op, |
| 3618 | SourceLocation RParenLoc) { |
| 3619 | // Use this for all of the locations, since we don't know the difference |
| 3620 | // between the call and the expr at this point. |
| 3621 | SourceRange Range{BuiltinLoc, RParenLoc}; |
| 3622 | return getSema().BuildAtomicExpr(Range, Range, RParenLoc, SubExprs, Op, |
| 3623 | Sema::AtomicArgumentOrder::AST); |
| 3624 | } |
| 3625 | |
| 3626 | ExprResult RebuildRecoveryExpr(SourceLocation BeginLoc, SourceLocation EndLoc, |
| 3627 | ArrayRef<Expr *> SubExprs, QualType Type) { |
| 3628 | return getSema().CreateRecoveryExpr(BeginLoc, EndLoc, SubExprs, Type); |
| 3629 | } |
| 3630 | |
| 3631 | private: |
| 3632 | TypeLoc TransformTypeInObjectScope(TypeLoc TL, |
| 3633 | QualType ObjectType, |
| 3634 | NamedDecl *FirstQualifierInScope, |
| 3635 | CXXScopeSpec &SS); |
| 3636 | |
| 3637 | TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 3638 | QualType ObjectType, |
| 3639 | NamedDecl *FirstQualifierInScope, |
| 3640 | CXXScopeSpec &SS); |
| 3641 | |
| 3642 | TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType, |
| 3643 | NamedDecl *FirstQualifierInScope, |
| 3644 | CXXScopeSpec &SS); |
| 3645 | |
| 3646 | QualType TransformDependentNameType(TypeLocBuilder &TLB, |
| 3647 | DependentNameTypeLoc TL, |
| 3648 | bool DeducibleTSTContext); |
| 3649 | }; |
| 3650 | |
| 3651 | template <typename Derived> |
| 3652 | StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S, StmtDiscardKind SDK) { |
| 3653 | if (!S) |
| 3654 | return S; |
| 3655 | |
| 3656 | switch (S->getStmtClass()) { |
| 3657 | case Stmt::NoStmtClass: break; |
| 3658 | |
| 3659 | // Transform individual statement nodes |
| 3660 | // Pass SDK into statements that can produce a value |
| 3661 | #define STMT(Node, Parent) \ |
| 3662 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); |
| 3663 | #define VALUESTMT(Node, Parent) \ |
| 3664 | case Stmt::Node##Class: \ |
| 3665 | return getDerived().Transform##Node(cast<Node>(S), SDK); |
| 3666 | #define ABSTRACT_STMT(Node) |
| 3667 | #define EXPR(Node, Parent) |
| 3668 | #include "clang/AST/StmtNodes.inc" |
| 3669 | |
| 3670 | // Transform expressions by calling TransformExpr. |
| 3671 | #define STMT(Node, Parent) |
| 3672 | #define ABSTRACT_STMT(Stmt) |
| 3673 | #define EXPR(Node, Parent) case Stmt::Node##Class: |
| 3674 | #include "clang/AST/StmtNodes.inc" |
| 3675 | { |
| 3676 | ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); |
| 3677 | |
| 3678 | if (SDK == SDK_StmtExprResult) |
| 3679 | E = getSema().ActOnStmtExprResult(E); |
| 3680 | return getSema().ActOnExprStmt(E, SDK == SDK_Discarded); |
| 3681 | } |
| 3682 | } |
| 3683 | |
| 3684 | return S; |
| 3685 | } |
| 3686 | |
| 3687 | template<typename Derived> |
| 3688 | OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) { |
| 3689 | if (!S) |
| 3690 | return S; |
| 3691 | |
| 3692 | switch (S->getClauseKind()) { |
| 3693 | default: break; |
| 3694 | // Transform individual clause nodes |
| 3695 | #define GEN_CLANG_CLAUSE_CLASS |
| 3696 | #define CLAUSE_CLASS(Enum, Str, Class) \ |
| 3697 | case Enum: \ |
| 3698 | return getDerived().Transform##Class(cast<Class>(S)); |
| 3699 | #include "llvm/Frontend/OpenMP/OMP.inc" |
| 3700 | } |
| 3701 | |
| 3702 | return S; |
| 3703 | } |
| 3704 | |
| 3705 | |
| 3706 | template<typename Derived> |
| 3707 | ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { |
| 3708 | if (!E) |
| 3709 | return E; |
| 3710 | |
| 3711 | switch (E->getStmtClass()) { |
| 3712 | case Stmt::NoStmtClass: break; |
| 3713 | #define STMT(Node, Parent) case Stmt::Node##Class: break; |
| 3714 | #define ABSTRACT_STMT(Stmt) |
| 3715 | #define EXPR(Node, Parent) \ |
| 3716 | case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); |
| 3717 | #include "clang/AST/StmtNodes.inc" |
| 3718 | } |
| 3719 | |
| 3720 | return E; |
| 3721 | } |
| 3722 | |
| 3723 | template<typename Derived> |
| 3724 | ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init, |
| 3725 | bool NotCopyInit) { |
| 3726 | // Initializers are instantiated like expressions, except that various outer |
| 3727 | // layers are stripped. |
| 3728 | if (!Init) |
| 3729 | return Init; |
| 3730 | |
| 3731 | if (auto *FE = dyn_cast<FullExpr>(Init)) |
| 3732 | Init = FE->getSubExpr(); |
| 3733 | |
| 3734 | if (auto *AIL = dyn_cast<ArrayInitLoopExpr>(Init)) |
| 3735 | Init = AIL->getCommonExpr(); |
| 3736 | |
| 3737 | if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init)) |
| 3738 | Init = MTE->getSubExpr(); |
| 3739 | |
| 3740 | while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init)) |
| 3741 | Init = Binder->getSubExpr(); |
| 3742 | |
| 3743 | if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init)) |
| 3744 | Init = ICE->getSubExprAsWritten(); |
| 3745 | |
| 3746 | if (CXXStdInitializerListExpr *ILE = |
| 3747 | dyn_cast<CXXStdInitializerListExpr>(Init)) |
| 3748 | return TransformInitializer(ILE->getSubExpr(), NotCopyInit); |
| 3749 | |
| 3750 | // If this is copy-initialization, we only need to reconstruct |
| 3751 | // InitListExprs. Other forms of copy-initialization will be a no-op if |
| 3752 | // the initializer is already the right type. |
| 3753 | CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init); |
| 3754 | if (!NotCopyInit && !(Construct && Construct->isListInitialization())) |
| 3755 | return getDerived().TransformExpr(Init); |
| 3756 | |
| 3757 | // Revert value-initialization back to empty parens. |
| 3758 | if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) { |
| 3759 | SourceRange Parens = VIE->getSourceRange(); |
| 3760 | return getDerived().RebuildParenListExpr(Parens.getBegin(), None, |
| 3761 | Parens.getEnd()); |
| 3762 | } |
| 3763 | |
| 3764 | // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization. |
| 3765 | if (isa<ImplicitValueInitExpr>(Init)) |
| 3766 | return getDerived().RebuildParenListExpr(SourceLocation(), None, |
| 3767 | SourceLocation()); |
| 3768 | |
| 3769 | // Revert initialization by constructor back to a parenthesized or braced list |
| 3770 | // of expressions. Any other form of initializer can just be reused directly. |
| 3771 | if (!Construct || isa<CXXTemporaryObjectExpr>(Construct)) |
| 3772 | return getDerived().TransformExpr(Init); |
| 3773 | |
| 3774 | // If the initialization implicitly converted an initializer list to a |
| 3775 | // std::initializer_list object, unwrap the std::initializer_list too. |
| 3776 | if (Construct && Construct->isStdInitListInitialization()) |
| 3777 | return TransformInitializer(Construct->getArg(0), NotCopyInit); |
| 3778 | |
| 3779 | // Enter a list-init context if this was list initialization. |
| 3780 | EnterExpressionEvaluationContext Context( |
| 3781 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 3782 | Construct->isListInitialization()); |
| 3783 | |
| 3784 | SmallVector<Expr*, 8> NewArgs; |
| 3785 | bool ArgChanged = false; |
| 3786 | if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(), |
| 3787 | /*IsCall*/true, NewArgs, &ArgChanged)) |
| 3788 | return ExprError(); |
| 3789 | |
| 3790 | // If this was list initialization, revert to syntactic list form. |
| 3791 | if (Construct->isListInitialization()) |
| 3792 | return getDerived().RebuildInitList(Construct->getBeginLoc(), NewArgs, |
| 3793 | Construct->getEndLoc()); |
| 3794 | |
| 3795 | // Build a ParenListExpr to represent anything else. |
| 3796 | SourceRange Parens = Construct->getParenOrBraceRange(); |
| 3797 | if (Parens.isInvalid()) { |
| 3798 | // This was a variable declaration's initialization for which no initializer |
| 3799 | // was specified. |
| 3800 | assert(NewArgs.empty() && |
| 3801 | "no parens or braces but have direct init with arguments?" ); |
| 3802 | return ExprEmpty(); |
| 3803 | } |
| 3804 | return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs, |
| 3805 | Parens.getEnd()); |
| 3806 | } |
| 3807 | |
| 3808 | template<typename Derived> |
| 3809 | bool TreeTransform<Derived>::TransformExprs(Expr *const *Inputs, |
| 3810 | unsigned NumInputs, |
| 3811 | bool IsCall, |
| 3812 | SmallVectorImpl<Expr *> &Outputs, |
| 3813 | bool *ArgChanged) { |
| 3814 | for (unsigned I = 0; I != NumInputs; ++I) { |
| 3815 | // If requested, drop call arguments that need to be dropped. |
| 3816 | if (IsCall && getDerived().DropCallArgument(Inputs[I])) { |
| 3817 | if (ArgChanged) |
| 3818 | *ArgChanged = true; |
| 3819 | |
| 3820 | break; |
| 3821 | } |
| 3822 | |
| 3823 | if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { |
| 3824 | Expr *Pattern = Expansion->getPattern(); |
| 3825 | |
| 3826 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 3827 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 3828 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?" ); |
| 3829 | |
| 3830 | // Determine whether the set of unexpanded parameter packs can and should |
| 3831 | // be expanded. |
| 3832 | bool Expand = true; |
| 3833 | bool RetainExpansion = false; |
| 3834 | Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions(); |
| 3835 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 3836 | if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), |
| 3837 | Pattern->getSourceRange(), |
| 3838 | Unexpanded, |
| 3839 | Expand, RetainExpansion, |
| 3840 | NumExpansions)) |
| 3841 | return true; |
| 3842 | |
| 3843 | if (!Expand) { |
| 3844 | // The transform has determined that we should perform a simple |
| 3845 | // transformation on the pack expansion, producing another pack |
| 3846 | // expansion. |
| 3847 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 3848 | ExprResult OutPattern = getDerived().TransformExpr(Pattern); |
| 3849 | if (OutPattern.isInvalid()) |
| 3850 | return true; |
| 3851 | |
| 3852 | ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), |
| 3853 | Expansion->getEllipsisLoc(), |
| 3854 | NumExpansions); |
| 3855 | if (Out.isInvalid()) |
| 3856 | return true; |
| 3857 | |
| 3858 | if (ArgChanged) |
| 3859 | *ArgChanged = true; |
| 3860 | Outputs.push_back(Out.get()); |
| 3861 | continue; |
| 3862 | } |
| 3863 | |
| 3864 | // Record right away that the argument was changed. This needs |
| 3865 | // to happen even if the array expands to nothing. |
| 3866 | if (ArgChanged) *ArgChanged = true; |
| 3867 | |
| 3868 | // The transform has determined that we should perform an elementwise |
| 3869 | // expansion of the pattern. Do so. |
| 3870 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 3871 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 3872 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3873 | if (Out.isInvalid()) |
| 3874 | return true; |
| 3875 | |
| 3876 | if (Out.get()->containsUnexpandedParameterPack()) { |
| 3877 | Out = getDerived().RebuildPackExpansion( |
| 3878 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3879 | if (Out.isInvalid()) |
| 3880 | return true; |
| 3881 | } |
| 3882 | |
| 3883 | Outputs.push_back(Out.get()); |
| 3884 | } |
| 3885 | |
| 3886 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 3887 | // forgetting the partially-substituted parameter pack. |
| 3888 | if (RetainExpansion) { |
| 3889 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 3890 | |
| 3891 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 3892 | if (Out.isInvalid()) |
| 3893 | return true; |
| 3894 | |
| 3895 | Out = getDerived().RebuildPackExpansion( |
| 3896 | Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions); |
| 3897 | if (Out.isInvalid()) |
| 3898 | return true; |
| 3899 | |
| 3900 | Outputs.push_back(Out.get()); |
| 3901 | } |
| 3902 | |
| 3903 | continue; |
| 3904 | } |
| 3905 | |
| 3906 | ExprResult Result = |
| 3907 | IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false) |
| 3908 | : getDerived().TransformExpr(Inputs[I]); |
| 3909 | if (Result.isInvalid()) |
| 3910 | return true; |
| 3911 | |
| 3912 | if (Result.get() != Inputs[I] && ArgChanged) |
| 3913 | *ArgChanged = true; |
| 3914 | |
| 3915 | Outputs.push_back(Result.get()); |
| 3916 | } |
| 3917 | |
| 3918 | return false; |
| 3919 | } |
| 3920 | |
| 3921 | template <typename Derived> |
| 3922 | Sema::ConditionResult TreeTransform<Derived>::TransformCondition( |
| 3923 | SourceLocation Loc, VarDecl *Var, Expr *Expr, Sema::ConditionKind Kind) { |
| 3924 | if (Var) { |
| 3925 | VarDecl *ConditionVar = cast_or_null<VarDecl>( |
| 3926 | getDerived().TransformDefinition(Var->getLocation(), Var)); |
| 3927 | |
| 3928 | if (!ConditionVar) |
| 3929 | return Sema::ConditionError(); |
| 3930 | |
| 3931 | return getSema().ActOnConditionVariable(ConditionVar, Loc, Kind); |
| 3932 | } |
| 3933 | |
| 3934 | if (Expr) { |
| 3935 | ExprResult CondExpr = getDerived().TransformExpr(Expr); |
| 3936 | |
| 3937 | if (CondExpr.isInvalid()) |
| 3938 | return Sema::ConditionError(); |
| 3939 | |
| 3940 | return getSema().ActOnCondition(nullptr, Loc, CondExpr.get(), Kind); |
| 3941 | } |
| 3942 | |
| 3943 | return Sema::ConditionResult(); |
| 3944 | } |
| 3945 | |
| 3946 | template<typename Derived> |
| 3947 | NestedNameSpecifierLoc |
| 3948 | TreeTransform<Derived>::TransformNestedNameSpecifierLoc( |
| 3949 | NestedNameSpecifierLoc NNS, |
| 3950 | QualType ObjectType, |
| 3951 | NamedDecl *FirstQualifierInScope) { |
| 3952 | SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; |
| 3953 | for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; |
| 3954 | Qualifier = Qualifier.getPrefix()) |
| 3955 | Qualifiers.push_back(Qualifier); |
| 3956 | |
| 3957 | CXXScopeSpec SS; |
| 3958 | while (!Qualifiers.empty()) { |
| 3959 | NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); |
| 3960 | NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); |
| 3961 | |
| 3962 | switch (QNNS->getKind()) { |
| 3963 | case NestedNameSpecifier::Identifier: { |
| 3964 | Sema::NestedNameSpecInfo IdInfo(QNNS->getAsIdentifier(), |
| 3965 | Q.getLocalBeginLoc(), Q.getLocalEndLoc(), ObjectType); |
| 3966 | if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr, IdInfo, false, |
| 3967 | SS, FirstQualifierInScope, false)) |
| 3968 | return NestedNameSpecifierLoc(); |
| 3969 | } |
| 3970 | break; |
| 3971 | |
| 3972 | case NestedNameSpecifier::Namespace: { |
| 3973 | NamespaceDecl *NS |
| 3974 | = cast_or_null<NamespaceDecl>( |
| 3975 | getDerived().TransformDecl( |
| 3976 | Q.getLocalBeginLoc(), |
| 3977 | QNNS->getAsNamespace())); |
| 3978 | SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); |
| 3979 | break; |
| 3980 | } |
| 3981 | |
| 3982 | case NestedNameSpecifier::NamespaceAlias: { |
| 3983 | NamespaceAliasDecl *Alias |
| 3984 | = cast_or_null<NamespaceAliasDecl>( |
| 3985 | getDerived().TransformDecl(Q.getLocalBeginLoc(), |
| 3986 | QNNS->getAsNamespaceAlias())); |
| 3987 | SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), |
| 3988 | Q.getLocalEndLoc()); |
| 3989 | break; |
| 3990 | } |
| 3991 | |
| 3992 | case NestedNameSpecifier::Global: |
| 3993 | // There is no meaningful transformation that one could perform on the |
| 3994 | // global scope. |
| 3995 | SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); |
| 3996 | break; |
| 3997 | |
| 3998 | case NestedNameSpecifier::Super: { |
| 3999 | CXXRecordDecl *RD = |
| 4000 | cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 4001 | SourceLocation(), QNNS->getAsRecordDecl())); |
| 4002 | SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc()); |
| 4003 | break; |
| 4004 | } |
| 4005 | |
| 4006 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 4007 | case NestedNameSpecifier::TypeSpec: { |
| 4008 | TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, |
| 4009 | FirstQualifierInScope, SS); |
| 4010 | |
| 4011 | if (!TL) |
| 4012 | return NestedNameSpecifierLoc(); |
| 4013 | |
| 4014 | if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || |
| 4015 | (SemaRef.getLangOpts().CPlusPlus11 && |
| 4016 | TL.getType()->isEnumeralType())) { |
| 4017 | assert(!TL.getType().hasLocalQualifiers() && |
| 4018 | "Can't get cv-qualifiers here" ); |
| 4019 | if (TL.getType()->isEnumeralType()) |
| 4020 | SemaRef.Diag(TL.getBeginLoc(), |
| 4021 | diag::warn_cxx98_compat_enum_nested_name_spec); |
| 4022 | SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, |
| 4023 | Q.getLocalEndLoc()); |
| 4024 | break; |
| 4025 | } |
| 4026 | // If the nested-name-specifier is an invalid type def, don't emit an |
| 4027 | // error because a previous error should have already been emitted. |
| 4028 | TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>(); |
| 4029 | if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) { |
| 4030 | SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) |
| 4031 | << TL.getType() << SS.getRange(); |
| 4032 | } |
| 4033 | return NestedNameSpecifierLoc(); |
| 4034 | } |
| 4035 | } |
| 4036 | |
| 4037 | // The qualifier-in-scope and object type only apply to the leftmost entity. |
| 4038 | FirstQualifierInScope = nullptr; |
| 4039 | ObjectType = QualType(); |
| 4040 | } |
| 4041 | |
| 4042 | // Don't rebuild the nested-name-specifier if we don't have to. |
| 4043 | if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && |
| 4044 | !getDerived().AlwaysRebuild()) |
| 4045 | return NNS; |
| 4046 | |
| 4047 | // If we can re-use the source-location data from the original |
| 4048 | // nested-name-specifier, do so. |
| 4049 | if (SS.location_size() == NNS.getDataLength() && |
| 4050 | memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) |
| 4051 | return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); |
| 4052 | |
| 4053 | // Allocate new nested-name-specifier location information. |
| 4054 | return SS.getWithLocInContext(SemaRef.Context); |
| 4055 | } |
| 4056 | |
| 4057 | template<typename Derived> |
| 4058 | DeclarationNameInfo |
| 4059 | TreeTransform<Derived> |
| 4060 | ::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { |
| 4061 | DeclarationName Name = NameInfo.getName(); |
| 4062 | if (!Name) |
| 4063 | return DeclarationNameInfo(); |
| 4064 | |
| 4065 | switch (Name.getNameKind()) { |
| 4066 | case DeclarationName::Identifier: |
| 4067 | case DeclarationName::ObjCZeroArgSelector: |
| 4068 | case DeclarationName::ObjCOneArgSelector: |
| 4069 | case DeclarationName::ObjCMultiArgSelector: |
| 4070 | case DeclarationName::CXXOperatorName: |
| 4071 | case DeclarationName::CXXLiteralOperatorName: |
| 4072 | case DeclarationName::CXXUsingDirective: |
| 4073 | return NameInfo; |
| 4074 | |
| 4075 | case DeclarationName::CXXDeductionGuideName: { |
| 4076 | TemplateDecl *OldTemplate = Name.getCXXDeductionGuideTemplate(); |
| 4077 | TemplateDecl *NewTemplate = cast_or_null<TemplateDecl>( |
| 4078 | getDerived().TransformDecl(NameInfo.getLoc(), OldTemplate)); |
| 4079 | if (!NewTemplate) |
| 4080 | return DeclarationNameInfo(); |
| 4081 | |
| 4082 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 4083 | NewNameInfo.setName( |
| 4084 | SemaRef.Context.DeclarationNames.getCXXDeductionGuideName(NewTemplate)); |
| 4085 | return NewNameInfo; |
| 4086 | } |
| 4087 | |
| 4088 | case DeclarationName::CXXConstructorName: |
| 4089 | case DeclarationName::CXXDestructorName: |
| 4090 | case DeclarationName::CXXConversionFunctionName: { |
| 4091 | TypeSourceInfo *NewTInfo; |
| 4092 | CanQualType NewCanTy; |
| 4093 | if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { |
| 4094 | NewTInfo = getDerived().TransformType(OldTInfo); |
| 4095 | if (!NewTInfo) |
| 4096 | return DeclarationNameInfo(); |
| 4097 | NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); |
| 4098 | } |
| 4099 | else { |
| 4100 | NewTInfo = nullptr; |
| 4101 | TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); |
| 4102 | QualType NewT = getDerived().TransformType(Name.getCXXNameType()); |
| 4103 | if (NewT.isNull()) |
| 4104 | return DeclarationNameInfo(); |
| 4105 | NewCanTy = SemaRef.Context.getCanonicalType(NewT); |
| 4106 | } |
| 4107 | |
| 4108 | DeclarationName NewName |
| 4109 | = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), |
| 4110 | NewCanTy); |
| 4111 | DeclarationNameInfo NewNameInfo(NameInfo); |
| 4112 | NewNameInfo.setName(NewName); |
| 4113 | NewNameInfo.setNamedTypeInfo(NewTInfo); |
| 4114 | return NewNameInfo; |
| 4115 | } |
| 4116 | } |
| 4117 | |
| 4118 | llvm_unreachable("Unknown name kind." ); |
| 4119 | } |
| 4120 | |
| 4121 | template<typename Derived> |
| 4122 | TemplateName |
| 4123 | TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, |
| 4124 | TemplateName Name, |
| 4125 | SourceLocation NameLoc, |
| 4126 | QualType ObjectType, |
| 4127 | NamedDecl *FirstQualifierInScope, |
| 4128 | bool AllowInjectedClassName) { |
| 4129 | if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { |
| 4130 | TemplateDecl *Template = QTN->getTemplateDecl(); |
| 4131 | assert(Template && "qualified template name must refer to a template" ); |
| 4132 | |
| 4133 | TemplateDecl *TransTemplate |
| 4134 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 4135 | Template)); |
| 4136 | if (!TransTemplate) |
| 4137 | return TemplateName(); |
| 4138 | |
| 4139 | if (!getDerived().AlwaysRebuild() && |
| 4140 | SS.getScopeRep() == QTN->getQualifier() && |
| 4141 | TransTemplate == Template) |
| 4142 | return Name; |
| 4143 | |
| 4144 | return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), |
| 4145 | TransTemplate); |
| 4146 | } |
| 4147 | |
| 4148 | if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { |
| 4149 | if (SS.getScopeRep()) { |
| 4150 | // These apply to the scope specifier, not the template. |
| 4151 | ObjectType = QualType(); |
| 4152 | FirstQualifierInScope = nullptr; |
| 4153 | } |
| 4154 | |
| 4155 | if (!getDerived().AlwaysRebuild() && |
| 4156 | SS.getScopeRep() == DTN->getQualifier() && |
| 4157 | ObjectType.isNull()) |
| 4158 | return Name; |
| 4159 | |
| 4160 | // FIXME: Preserve the location of the "template" keyword. |
| 4161 | SourceLocation TemplateKWLoc = NameLoc; |
| 4162 | |
| 4163 | if (DTN->isIdentifier()) { |
| 4164 | return getDerived().RebuildTemplateName(SS, |
| 4165 | TemplateKWLoc, |
| 4166 | *DTN->getIdentifier(), |
| 4167 | NameLoc, |
| 4168 | ObjectType, |
| 4169 | FirstQualifierInScope, |
| 4170 | AllowInjectedClassName); |
| 4171 | } |
| 4172 | |
| 4173 | return getDerived().RebuildTemplateName(SS, TemplateKWLoc, |
| 4174 | DTN->getOperator(), NameLoc, |
| 4175 | ObjectType, AllowInjectedClassName); |
| 4176 | } |
| 4177 | |
| 4178 | if (TemplateDecl *Template = Name.getAsTemplateDecl()) { |
| 4179 | TemplateDecl *TransTemplate |
| 4180 | = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, |
| 4181 | Template)); |
| 4182 | if (!TransTemplate) |
| 4183 | return TemplateName(); |
| 4184 | |
| 4185 | if (!getDerived().AlwaysRebuild() && |
| 4186 | TransTemplate == Template) |
| 4187 | return Name; |
| 4188 | |
| 4189 | return TemplateName(TransTemplate); |
| 4190 | } |
| 4191 | |
| 4192 | if (SubstTemplateTemplateParmPackStorage *SubstPack |
| 4193 | = Name.getAsSubstTemplateTemplateParmPack()) { |
| 4194 | TemplateTemplateParmDecl *TransParam |
| 4195 | = cast_or_null<TemplateTemplateParmDecl>( |
| 4196 | getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); |
| 4197 | if (!TransParam) |
| 4198 | return TemplateName(); |
| 4199 | |
| 4200 | if (!getDerived().AlwaysRebuild() && |
| 4201 | TransParam == SubstPack->getParameterPack()) |
| 4202 | return Name; |
| 4203 | |
| 4204 | return getDerived().RebuildTemplateName(TransParam, |
| 4205 | SubstPack->getArgumentPack()); |
| 4206 | } |
| 4207 | |
| 4208 | // These should be getting filtered out before they reach the AST. |
| 4209 | llvm_unreachable("overloaded function decl survived to here" ); |
| 4210 | } |
| 4211 | |
| 4212 | template<typename Derived> |
| 4213 | void TreeTransform<Derived>::InventTemplateArgumentLoc( |
| 4214 | const TemplateArgument &Arg, |
| 4215 | TemplateArgumentLoc &Output) { |
| 4216 | Output = getSema().getTrivialTemplateArgumentLoc( |
| 4217 | Arg, QualType(), getDerived().getBaseLocation()); |
| 4218 | } |
| 4219 | |
| 4220 | template<typename Derived> |
| 4221 | bool TreeTransform<Derived>::TransformTemplateArgument( |
| 4222 | const TemplateArgumentLoc &Input, |
| 4223 | TemplateArgumentLoc &Output, bool Uneval) { |
| 4224 | const TemplateArgument &Arg = Input.getArgument(); |
| 4225 | switch (Arg.getKind()) { |
| 4226 | case TemplateArgument::Null: |
| 4227 | case TemplateArgument::Pack: |
| 4228 | llvm_unreachable("Unexpected TemplateArgument" ); |
| 4229 | |
| 4230 | case TemplateArgument::Integral: |
| 4231 | case TemplateArgument::NullPtr: |
| 4232 | case TemplateArgument::Declaration: { |
| 4233 | // Transform a resolved template argument straight to a resolved template |
| 4234 | // argument. We get here when substituting into an already-substituted |
| 4235 | // template type argument during concept satisfaction checking. |
| 4236 | QualType T = Arg.getNonTypeTemplateArgumentType(); |
| 4237 | QualType NewT = getDerived().TransformType(T); |
| 4238 | if (NewT.isNull()) |
| 4239 | return true; |
| 4240 | |
| 4241 | ValueDecl *D = Arg.getKind() == TemplateArgument::Declaration |
| 4242 | ? Arg.getAsDecl() |
| 4243 | : nullptr; |
| 4244 | ValueDecl *NewD = D ? cast_or_null<ValueDecl>(getDerived().TransformDecl( |
| 4245 | getDerived().getBaseLocation(), D)) |
| 4246 | : nullptr; |
| 4247 | if (D && !NewD) |
| 4248 | return true; |
| 4249 | |
| 4250 | if (NewT == T && D == NewD) |
| 4251 | Output = Input; |
| 4252 | else if (Arg.getKind() == TemplateArgument::Integral) |
| 4253 | Output = TemplateArgumentLoc( |
| 4254 | TemplateArgument(getSema().Context, Arg.getAsIntegral(), NewT), |
| 4255 | TemplateArgumentLocInfo()); |
| 4256 | else if (Arg.getKind() == TemplateArgument::NullPtr) |
| 4257 | Output = TemplateArgumentLoc(TemplateArgument(NewT, /*IsNullPtr=*/true), |
| 4258 | TemplateArgumentLocInfo()); |
| 4259 | else |
| 4260 | Output = TemplateArgumentLoc(TemplateArgument(NewD, NewT), |
| 4261 | TemplateArgumentLocInfo()); |
| 4262 | |
| 4263 | return false; |
| 4264 | } |
| 4265 | |
| 4266 | case TemplateArgument::Type: { |
| 4267 | TypeSourceInfo *DI = Input.getTypeSourceInfo(); |
| 4268 | if (!DI) |
| 4269 | DI = InventTypeSourceInfo(Input.getArgument().getAsType()); |
| 4270 | |
| 4271 | DI = getDerived().TransformType(DI); |
| 4272 | if (!DI) return true; |
| 4273 | |
| 4274 | Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); |
| 4275 | return false; |
| 4276 | } |
| 4277 | |
| 4278 | case TemplateArgument::Template: { |
| 4279 | NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); |
| 4280 | if (QualifierLoc) { |
| 4281 | QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); |
| 4282 | if (!QualifierLoc) |
| 4283 | return true; |
| 4284 | } |
| 4285 | |
| 4286 | CXXScopeSpec SS; |
| 4287 | SS.Adopt(QualifierLoc); |
| 4288 | TemplateName Template |
| 4289 | = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), |
| 4290 | Input.getTemplateNameLoc()); |
| 4291 | if (Template.isNull()) |
| 4292 | return true; |
| 4293 | |
| 4294 | Output = TemplateArgumentLoc(SemaRef.Context, TemplateArgument(Template), |
| 4295 | QualifierLoc, Input.getTemplateNameLoc()); |
| 4296 | return false; |
| 4297 | } |
| 4298 | |
| 4299 | case TemplateArgument::TemplateExpansion: |
| 4300 | llvm_unreachable("Caller should expand pack expansions" ); |
| 4301 | |
| 4302 | case TemplateArgument::Expression: { |
| 4303 | // Template argument expressions are constant expressions. |
| 4304 | EnterExpressionEvaluationContext Unevaluated( |
| 4305 | getSema(), |
| 4306 | Uneval ? Sema::ExpressionEvaluationContext::Unevaluated |
| 4307 | : Sema::ExpressionEvaluationContext::ConstantEvaluated, |
| 4308 | /*LambdaContextDecl=*/nullptr, /*ExprContext=*/ |
| 4309 | Sema::ExpressionEvaluationContextRecord::EK_TemplateArgument); |
| 4310 | |
| 4311 | Expr *InputExpr = Input.getSourceExpression(); |
| 4312 | if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); |
| 4313 | |
| 4314 | ExprResult E = getDerived().TransformExpr(InputExpr); |
| 4315 | E = SemaRef.ActOnConstantExpression(E); |
| 4316 | if (E.isInvalid()) return true; |
| 4317 | Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get()); |
| 4318 | return false; |
| 4319 | } |
| 4320 | } |
| 4321 | |
| 4322 | // Work around bogus GCC warning |
| 4323 | return true; |
| 4324 | } |
| 4325 | |
| 4326 | /// Iterator adaptor that invents template argument location information |
| 4327 | /// for each of the template arguments in its underlying iterator. |
| 4328 | template<typename Derived, typename InputIterator> |
| 4329 | class TemplateArgumentLocInventIterator { |
| 4330 | TreeTransform<Derived> &Self; |
| 4331 | InputIterator Iter; |
| 4332 | |
| 4333 | public: |
| 4334 | typedef TemplateArgumentLoc value_type; |
| 4335 | typedef TemplateArgumentLoc reference; |
| 4336 | typedef typename std::iterator_traits<InputIterator>::difference_type |
| 4337 | difference_type; |
| 4338 | typedef std::input_iterator_tag iterator_category; |
| 4339 | |
| 4340 | class pointer { |
| 4341 | TemplateArgumentLoc Arg; |
| 4342 | |
| 4343 | public: |
| 4344 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 4345 | |
| 4346 | const TemplateArgumentLoc *operator->() const { return &Arg; } |
| 4347 | }; |
| 4348 | |
| 4349 | TemplateArgumentLocInventIterator() { } |
| 4350 | |
| 4351 | explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, |
| 4352 | InputIterator Iter) |
| 4353 | : Self(Self), Iter(Iter) { } |
| 4354 | |
| 4355 | TemplateArgumentLocInventIterator &operator++() { |
| 4356 | ++Iter; |
| 4357 | return *this; |
| 4358 | } |
| 4359 | |
| 4360 | TemplateArgumentLocInventIterator operator++(int) { |
| 4361 | TemplateArgumentLocInventIterator Old(*this); |
| 4362 | ++(*this); |
| 4363 | return Old; |
| 4364 | } |
| 4365 | |
| 4366 | reference operator*() const { |
| 4367 | TemplateArgumentLoc Result; |
| 4368 | Self.InventTemplateArgumentLoc(*Iter, Result); |
| 4369 | return Result; |
| 4370 | } |
| 4371 | |
| 4372 | pointer operator->() const { return pointer(**this); } |
| 4373 | |
| 4374 | friend bool operator==(const TemplateArgumentLocInventIterator &X, |
| 4375 | const TemplateArgumentLocInventIterator &Y) { |
| 4376 | return X.Iter == Y.Iter; |
| 4377 | } |
| 4378 | |
| 4379 | friend bool operator!=(const TemplateArgumentLocInventIterator &X, |
| 4380 | const TemplateArgumentLocInventIterator &Y) { |
| 4381 | return X.Iter != Y.Iter; |
| 4382 | } |
| 4383 | }; |
| 4384 | |
| 4385 | template<typename Derived> |
| 4386 | template<typename InputIterator> |
| 4387 | bool TreeTransform<Derived>::TransformTemplateArguments( |
| 4388 | InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs, |
| 4389 | bool Uneval) { |
| 4390 | for (; First != Last; ++First) { |
| 4391 | TemplateArgumentLoc Out; |
| 4392 | TemplateArgumentLoc In = *First; |
| 4393 | |
| 4394 | if (In.getArgument().getKind() == TemplateArgument::Pack) { |
| 4395 | // Unpack argument packs, which we translate them into separate |
| 4396 | // arguments. |
| 4397 | // FIXME: We could do much better if we could guarantee that the |
| 4398 | // TemplateArgumentLocInfo for the pack expansion would be usable for |
| 4399 | // all of the template arguments in the argument pack. |
| 4400 | typedef TemplateArgumentLocInventIterator<Derived, |
| 4401 | TemplateArgument::pack_iterator> |
| 4402 | PackLocIterator; |
| 4403 | if (TransformTemplateArguments(PackLocIterator(*this, |
| 4404 | In.getArgument().pack_begin()), |
| 4405 | PackLocIterator(*this, |
| 4406 | In.getArgument().pack_end()), |
| 4407 | Outputs, Uneval)) |
| 4408 | return true; |
| 4409 | |
| 4410 | continue; |
| 4411 | } |
| 4412 | |
| 4413 | if (In.getArgument().isPackExpansion()) { |
| 4414 | // We have a pack expansion, for which we will be substituting into |
| 4415 | // the pattern. |
| 4416 | SourceLocation Ellipsis; |
| 4417 | Optional<unsigned> OrigNumExpansions; |
| 4418 | TemplateArgumentLoc Pattern |
| 4419 | = getSema().getTemplateArgumentPackExpansionPattern( |
| 4420 | In, Ellipsis, OrigNumExpansions); |
| 4421 | |
| 4422 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 4423 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 4424 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?" ); |
| 4425 | |
| 4426 | // Determine whether the set of unexpanded parameter packs can and should |
| 4427 | // be expanded. |
| 4428 | bool Expand = true; |
| 4429 | bool RetainExpansion = false; |
| 4430 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 4431 | if (getDerived().TryExpandParameterPacks(Ellipsis, |
| 4432 | Pattern.getSourceRange(), |
| 4433 | Unexpanded, |
| 4434 | Expand, |
| 4435 | RetainExpansion, |
| 4436 | NumExpansions)) |
| 4437 | return true; |
| 4438 | |
| 4439 | if (!Expand) { |
| 4440 | // The transform has determined that we should perform a simple |
| 4441 | // transformation on the pack expansion, producing another pack |
| 4442 | // expansion. |
| 4443 | TemplateArgumentLoc OutPattern; |
| 4444 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 4445 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval)) |
| 4446 | return true; |
| 4447 | |
| 4448 | Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, |
| 4449 | NumExpansions); |
| 4450 | if (Out.getArgument().isNull()) |
| 4451 | return true; |
| 4452 | |
| 4453 | Outputs.addArgument(Out); |
| 4454 | continue; |
| 4455 | } |
| 4456 | |
| 4457 | // The transform has determined that we should perform an elementwise |
| 4458 | // expansion of the pattern. Do so. |
| 4459 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 4460 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 4461 | |
| 4462 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
| 4463 | return true; |
| 4464 | |
| 4465 | if (Out.getArgument().containsUnexpandedParameterPack()) { |
| 4466 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 4467 | OrigNumExpansions); |
| 4468 | if (Out.getArgument().isNull()) |
| 4469 | return true; |
| 4470 | } |
| 4471 | |
| 4472 | Outputs.addArgument(Out); |
| 4473 | } |
| 4474 | |
| 4475 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 4476 | // forgetting the partially-substituted parameter pack. |
| 4477 | if (RetainExpansion) { |
| 4478 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 4479 | |
| 4480 | if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval)) |
| 4481 | return true; |
| 4482 | |
| 4483 | Out = getDerived().RebuildPackExpansion(Out, Ellipsis, |
| 4484 | OrigNumExpansions); |
| 4485 | if (Out.getArgument().isNull()) |
| 4486 | return true; |
| 4487 | |
| 4488 | Outputs.addArgument(Out); |
| 4489 | } |
| 4490 | |
| 4491 | continue; |
| 4492 | } |
| 4493 | |
| 4494 | // The simple case: |
| 4495 | if (getDerived().TransformTemplateArgument(In, Out, Uneval)) |
| 4496 | return true; |
| 4497 | |
| 4498 | Outputs.addArgument(Out); |
| 4499 | } |
| 4500 | |
| 4501 | return false; |
| 4502 | |
| 4503 | } |
| 4504 | |
| 4505 | //===----------------------------------------------------------------------===// |
| 4506 | // Type transformation |
| 4507 | //===----------------------------------------------------------------------===// |
| 4508 | |
| 4509 | template<typename Derived> |
| 4510 | QualType TreeTransform<Derived>::TransformType(QualType T) { |
| 4511 | if (getDerived().AlreadyTransformed(T)) |
| 4512 | return T; |
| 4513 | |
| 4514 | // Temporary workaround. All of these transformations should |
| 4515 | // eventually turn into transformations on TypeLocs. |
| 4516 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 4517 | getDerived().getBaseLocation()); |
| 4518 | |
| 4519 | TypeSourceInfo *NewDI = getDerived().TransformType(DI); |
| 4520 | |
| 4521 | if (!NewDI) |
| 4522 | return QualType(); |
| 4523 | |
| 4524 | return NewDI->getType(); |
| 4525 | } |
| 4526 | |
| 4527 | template<typename Derived> |
| 4528 | TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { |
| 4529 | // Refine the base location to the type's location. |
| 4530 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 4531 | getDerived().getBaseEntity()); |
| 4532 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 4533 | return DI; |
| 4534 | |
| 4535 | TypeLocBuilder TLB; |
| 4536 | |
| 4537 | TypeLoc TL = DI->getTypeLoc(); |
| 4538 | TLB.reserve(TL.getFullDataSize()); |
| 4539 | |
| 4540 | QualType Result = getDerived().TransformType(TLB, TL); |
| 4541 | if (Result.isNull()) |
| 4542 | return nullptr; |
| 4543 | |
| 4544 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4545 | } |
| 4546 | |
| 4547 | template<typename Derived> |
| 4548 | QualType |
| 4549 | TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { |
| 4550 | switch (T.getTypeLocClass()) { |
| 4551 | #define ABSTRACT_TYPELOC(CLASS, PARENT) |
| 4552 | #define TYPELOC(CLASS, PARENT) \ |
| 4553 | case TypeLoc::CLASS: \ |
| 4554 | return getDerived().Transform##CLASS##Type(TLB, \ |
| 4555 | T.castAs<CLASS##TypeLoc>()); |
| 4556 | #include "clang/AST/TypeLocNodes.def" |
| 4557 | } |
| 4558 | |
| 4559 | llvm_unreachable("unhandled type loc!" ); |
| 4560 | } |
| 4561 | |
| 4562 | template<typename Derived> |
| 4563 | QualType TreeTransform<Derived>::TransformTypeWithDeducedTST(QualType T) { |
| 4564 | if (!isa<DependentNameType>(T)) |
| 4565 | return TransformType(T); |
| 4566 | |
| 4567 | if (getDerived().AlreadyTransformed(T)) |
| 4568 | return T; |
| 4569 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, |
| 4570 | getDerived().getBaseLocation()); |
| 4571 | TypeSourceInfo *NewDI = getDerived().TransformTypeWithDeducedTST(DI); |
| 4572 | return NewDI ? NewDI->getType() : QualType(); |
| 4573 | } |
| 4574 | |
| 4575 | template<typename Derived> |
| 4576 | TypeSourceInfo * |
| 4577 | TreeTransform<Derived>::TransformTypeWithDeducedTST(TypeSourceInfo *DI) { |
| 4578 | if (!isa<DependentNameType>(DI->getType())) |
| 4579 | return TransformType(DI); |
| 4580 | |
| 4581 | // Refine the base location to the type's location. |
| 4582 | TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), |
| 4583 | getDerived().getBaseEntity()); |
| 4584 | if (getDerived().AlreadyTransformed(DI->getType())) |
| 4585 | return DI; |
| 4586 | |
| 4587 | TypeLocBuilder TLB; |
| 4588 | |
| 4589 | TypeLoc TL = DI->getTypeLoc(); |
| 4590 | TLB.reserve(TL.getFullDataSize()); |
| 4591 | |
| 4592 | auto QTL = TL.getAs<QualifiedTypeLoc>(); |
| 4593 | if (QTL) |
| 4594 | TL = QTL.getUnqualifiedLoc(); |
| 4595 | |
| 4596 | auto DNTL = TL.castAs<DependentNameTypeLoc>(); |
| 4597 | |
| 4598 | QualType Result = getDerived().TransformDependentNameType( |
| 4599 | TLB, DNTL, /*DeducedTSTContext*/true); |
| 4600 | if (Result.isNull()) |
| 4601 | return nullptr; |
| 4602 | |
| 4603 | if (QTL) { |
| 4604 | Result = getDerived().RebuildQualifiedType(Result, QTL); |
| 4605 | if (Result.isNull()) |
| 4606 | return nullptr; |
| 4607 | TLB.TypeWasModifiedSafely(Result); |
| 4608 | } |
| 4609 | |
| 4610 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4611 | } |
| 4612 | |
| 4613 | template<typename Derived> |
| 4614 | QualType |
| 4615 | TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, |
| 4616 | QualifiedTypeLoc T) { |
| 4617 | QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); |
| 4618 | if (Result.isNull()) |
| 4619 | return QualType(); |
| 4620 | |
| 4621 | Result = getDerived().RebuildQualifiedType(Result, T); |
| 4622 | |
| 4623 | if (Result.isNull()) |
| 4624 | return QualType(); |
| 4625 | |
| 4626 | // RebuildQualifiedType might have updated the type, but not in a way |
| 4627 | // that invalidates the TypeLoc. (There's no location information for |
| 4628 | // qualifiers.) |
| 4629 | TLB.TypeWasModifiedSafely(Result); |
| 4630 | |
| 4631 | return Result; |
| 4632 | } |
| 4633 | |
| 4634 | template <typename Derived> |
| 4635 | QualType TreeTransform<Derived>::RebuildQualifiedType(QualType T, |
| 4636 | QualifiedTypeLoc TL) { |
| 4637 | |
| 4638 | SourceLocation Loc = TL.getBeginLoc(); |
| 4639 | Qualifiers Quals = TL.getType().getLocalQualifiers(); |
| 4640 | |
| 4641 | if (((T.getAddressSpace() != LangAS::Default && |
| 4642 | Quals.getAddressSpace() != LangAS::Default)) && |
| 4643 | T.getAddressSpace() != Quals.getAddressSpace()) { |
| 4644 | SemaRef.Diag(Loc, diag::err_address_space_mismatch_templ_inst) |
| 4645 | << TL.getType() << T; |
| 4646 | return QualType(); |
| 4647 | } |
| 4648 | |
| 4649 | // C++ [dcl.fct]p7: |
| 4650 | // [When] adding cv-qualifications on top of the function type [...] the |
| 4651 | // cv-qualifiers are ignored. |
| 4652 | if (T->isFunctionType()) { |
| 4653 | T = SemaRef.getASTContext().getAddrSpaceQualType(T, |
| 4654 | Quals.getAddressSpace()); |
| 4655 | return T; |
| 4656 | } |
| 4657 | |
| 4658 | // C++ [dcl.ref]p1: |
| 4659 | // when the cv-qualifiers are introduced through the use of a typedef-name |
| 4660 | // or decltype-specifier [...] the cv-qualifiers are ignored. |
| 4661 | // Note that [dcl.ref]p1 lists all cases in which cv-qualifiers can be |
| 4662 | // applied to a reference type. |
| 4663 | if (T->isReferenceType()) { |
| 4664 | // The only qualifier that applies to a reference type is restrict. |
| 4665 | if (!Quals.hasRestrict()) |
| 4666 | return T; |
| 4667 | Quals = Qualifiers::fromCVRMask(Qualifiers::Restrict); |
| 4668 | } |
| 4669 | |
| 4670 | // Suppress Objective-C lifetime qualifiers if they don't make sense for the |
| 4671 | // resulting type. |
| 4672 | if (Quals.hasObjCLifetime()) { |
| 4673 | if (!T->isObjCLifetimeType() && !T->isDependentType()) |
| 4674 | Quals.removeObjCLifetime(); |
| 4675 | else if (T.getObjCLifetime()) { |
| 4676 | // Objective-C ARC: |
| 4677 | // A lifetime qualifier applied to a substituted template parameter |
| 4678 | // overrides the lifetime qualifier from the template argument. |
| 4679 | const AutoType *AutoTy; |
| 4680 | if (const SubstTemplateTypeParmType *SubstTypeParam |
| 4681 | = dyn_cast<SubstTemplateTypeParmType>(T)) { |
| 4682 | QualType Replacement = SubstTypeParam->getReplacementType(); |
| 4683 | Qualifiers Qs = Replacement.getQualifiers(); |
| 4684 | Qs.removeObjCLifetime(); |
| 4685 | Replacement = SemaRef.Context.getQualifiedType( |
| 4686 | Replacement.getUnqualifiedType(), Qs); |
| 4687 | T = SemaRef.Context.getSubstTemplateTypeParmType( |
| 4688 | SubstTypeParam->getReplacedParameter(), Replacement); |
| 4689 | } else if ((AutoTy = dyn_cast<AutoType>(T)) && AutoTy->isDeduced()) { |
| 4690 | // 'auto' types behave the same way as template parameters. |
| 4691 | QualType Deduced = AutoTy->getDeducedType(); |
| 4692 | Qualifiers Qs = Deduced.getQualifiers(); |
| 4693 | Qs.removeObjCLifetime(); |
| 4694 | Deduced = |
| 4695 | SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(), Qs); |
| 4696 | T = SemaRef.Context.getAutoType(Deduced, AutoTy->getKeyword(), |
| 4697 | AutoTy->isDependentType(), |
| 4698 | /*isPack=*/false, |
| 4699 | AutoTy->getTypeConstraintConcept(), |
| 4700 | AutoTy->getTypeConstraintArguments()); |
| 4701 | } else { |
| 4702 | // Otherwise, complain about the addition of a qualifier to an |
| 4703 | // already-qualified type. |
| 4704 | // FIXME: Why is this check not in Sema::BuildQualifiedType? |
| 4705 | SemaRef.Diag(Loc, diag::err_attr_objc_ownership_redundant) << T; |
| 4706 | Quals.removeObjCLifetime(); |
| 4707 | } |
| 4708 | } |
| 4709 | } |
| 4710 | |
| 4711 | return SemaRef.BuildQualifiedType(T, Loc, Quals); |
| 4712 | } |
| 4713 | |
| 4714 | template<typename Derived> |
| 4715 | TypeLoc |
| 4716 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, |
| 4717 | QualType ObjectType, |
| 4718 | NamedDecl *UnqualLookup, |
| 4719 | CXXScopeSpec &SS) { |
| 4720 | if (getDerived().AlreadyTransformed(TL.getType())) |
| 4721 | return TL; |
| 4722 | |
| 4723 | TypeSourceInfo *TSI = |
| 4724 | TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS); |
| 4725 | if (TSI) |
| 4726 | return TSI->getTypeLoc(); |
| 4727 | return TypeLoc(); |
| 4728 | } |
| 4729 | |
| 4730 | template<typename Derived> |
| 4731 | TypeSourceInfo * |
| 4732 | TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, |
| 4733 | QualType ObjectType, |
| 4734 | NamedDecl *UnqualLookup, |
| 4735 | CXXScopeSpec &SS) { |
| 4736 | if (getDerived().AlreadyTransformed(TSInfo->getType())) |
| 4737 | return TSInfo; |
| 4738 | |
| 4739 | return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType, |
| 4740 | UnqualLookup, SS); |
| 4741 | } |
| 4742 | |
| 4743 | template <typename Derived> |
| 4744 | TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope( |
| 4745 | TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup, |
| 4746 | CXXScopeSpec &SS) { |
| 4747 | QualType T = TL.getType(); |
| 4748 | assert(!getDerived().AlreadyTransformed(T)); |
| 4749 | |
| 4750 | TypeLocBuilder TLB; |
| 4751 | QualType Result; |
| 4752 | |
| 4753 | if (isa<TemplateSpecializationType>(T)) { |
| 4754 | TemplateSpecializationTypeLoc SpecTL = |
| 4755 | TL.castAs<TemplateSpecializationTypeLoc>(); |
| 4756 | |
| 4757 | TemplateName Template = getDerived().TransformTemplateName( |
| 4758 | SS, SpecTL.getTypePtr()->getTemplateName(), SpecTL.getTemplateNameLoc(), |
| 4759 | ObjectType, UnqualLookup, /*AllowInjectedClassName*/true); |
| 4760 | if (Template.isNull()) |
| 4761 | return nullptr; |
| 4762 | |
| 4763 | Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, |
| 4764 | Template); |
| 4765 | } else if (isa<DependentTemplateSpecializationType>(T)) { |
| 4766 | DependentTemplateSpecializationTypeLoc SpecTL = |
| 4767 | TL.castAs<DependentTemplateSpecializationTypeLoc>(); |
| 4768 | |
| 4769 | TemplateName Template |
| 4770 | = getDerived().RebuildTemplateName(SS, |
| 4771 | SpecTL.getTemplateKeywordLoc(), |
| 4772 | *SpecTL.getTypePtr()->getIdentifier(), |
| 4773 | SpecTL.getTemplateNameLoc(), |
| 4774 | ObjectType, UnqualLookup, |
| 4775 | /*AllowInjectedClassName*/true); |
| 4776 | if (Template.isNull()) |
| 4777 | return nullptr; |
| 4778 | |
| 4779 | Result = getDerived().TransformDependentTemplateSpecializationType(TLB, |
| 4780 | SpecTL, |
| 4781 | Template, |
| 4782 | SS); |
| 4783 | } else { |
| 4784 | // Nothing special needs to be done for these. |
| 4785 | Result = getDerived().TransformType(TLB, TL); |
| 4786 | } |
| 4787 | |
| 4788 | if (Result.isNull()) |
| 4789 | return nullptr; |
| 4790 | |
| 4791 | return TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 4792 | } |
| 4793 | |
| 4794 | template <class TyLoc> static inline |
| 4795 | QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { |
| 4796 | TyLoc NewT = TLB.push<TyLoc>(T.getType()); |
| 4797 | NewT.setNameLoc(T.getNameLoc()); |
| 4798 | return T.getType(); |
| 4799 | } |
| 4800 | |
| 4801 | template<typename Derived> |
| 4802 | QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, |
| 4803 | BuiltinTypeLoc T) { |
| 4804 | BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); |
| 4805 | NewT.setBuiltinLoc(T.getBuiltinLoc()); |
| 4806 | if (T.needsExtraLocalData()) |
| 4807 | NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); |
| 4808 | return T.getType(); |
| 4809 | } |
| 4810 | |
| 4811 | template<typename Derived> |
| 4812 | QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, |
| 4813 | ComplexTypeLoc T) { |
| 4814 | // FIXME: recurse? |
| 4815 | return TransformTypeSpecType(TLB, T); |
| 4816 | } |
| 4817 | |
| 4818 | template <typename Derived> |
| 4819 | QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB, |
| 4820 | AdjustedTypeLoc TL) { |
| 4821 | // Adjustments applied during transformation are handled elsewhere. |
| 4822 | return getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4823 | } |
| 4824 | |
| 4825 | template<typename Derived> |
| 4826 | QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB, |
| 4827 | DecayedTypeLoc TL) { |
| 4828 | QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc()); |
| 4829 | if (OriginalType.isNull()) |
| 4830 | return QualType(); |
| 4831 | |
| 4832 | QualType Result = TL.getType(); |
| 4833 | if (getDerived().AlwaysRebuild() || |
| 4834 | OriginalType != TL.getOriginalLoc().getType()) |
| 4835 | Result = SemaRef.Context.getDecayedType(OriginalType); |
| 4836 | TLB.push<DecayedTypeLoc>(Result); |
| 4837 | // Nothing to set for DecayedTypeLoc. |
| 4838 | return Result; |
| 4839 | } |
| 4840 | |
| 4841 | template<typename Derived> |
| 4842 | QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, |
| 4843 | PointerTypeLoc TL) { |
| 4844 | QualType PointeeType |
| 4845 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4846 | if (PointeeType.isNull()) |
| 4847 | return QualType(); |
| 4848 | |
| 4849 | QualType Result = TL.getType(); |
| 4850 | if (PointeeType->getAs<ObjCObjectType>()) { |
| 4851 | // A dependent pointer type 'T *' has is being transformed such |
| 4852 | // that an Objective-C class type is being replaced for 'T'. The |
| 4853 | // resulting pointer type is an ObjCObjectPointerType, not a |
| 4854 | // PointerType. |
| 4855 | Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| 4856 | |
| 4857 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 4858 | NewT.setStarLoc(TL.getStarLoc()); |
| 4859 | return Result; |
| 4860 | } |
| 4861 | |
| 4862 | if (getDerived().AlwaysRebuild() || |
| 4863 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4864 | Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); |
| 4865 | if (Result.isNull()) |
| 4866 | return QualType(); |
| 4867 | } |
| 4868 | |
| 4869 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4870 | // pointing to. |
| 4871 | TLB.TypeWasModifiedSafely(Result->getPointeeType()); |
| 4872 | |
| 4873 | PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); |
| 4874 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 4875 | return Result; |
| 4876 | } |
| 4877 | |
| 4878 | template<typename Derived> |
| 4879 | QualType |
| 4880 | TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, |
| 4881 | BlockPointerTypeLoc TL) { |
| 4882 | QualType PointeeType |
| 4883 | = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4884 | if (PointeeType.isNull()) |
| 4885 | return QualType(); |
| 4886 | |
| 4887 | QualType Result = TL.getType(); |
| 4888 | if (getDerived().AlwaysRebuild() || |
| 4889 | PointeeType != TL.getPointeeLoc().getType()) { |
| 4890 | Result = getDerived().RebuildBlockPointerType(PointeeType, |
| 4891 | TL.getSigilLoc()); |
| 4892 | if (Result.isNull()) |
| 4893 | return QualType(); |
| 4894 | } |
| 4895 | |
| 4896 | BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); |
| 4897 | NewT.setSigilLoc(TL.getSigilLoc()); |
| 4898 | return Result; |
| 4899 | } |
| 4900 | |
| 4901 | /// Transforms a reference type. Note that somewhat paradoxically we |
| 4902 | /// don't care whether the type itself is an l-value type or an r-value |
| 4903 | /// type; we only care if the type was *written* as an l-value type |
| 4904 | /// or an r-value type. |
| 4905 | template<typename Derived> |
| 4906 | QualType |
| 4907 | TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, |
| 4908 | ReferenceTypeLoc TL) { |
| 4909 | const ReferenceType *T = TL.getTypePtr(); |
| 4910 | |
| 4911 | // Note that this works with the pointee-as-written. |
| 4912 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4913 | if (PointeeType.isNull()) |
| 4914 | return QualType(); |
| 4915 | |
| 4916 | QualType Result = TL.getType(); |
| 4917 | if (getDerived().AlwaysRebuild() || |
| 4918 | PointeeType != T->getPointeeTypeAsWritten()) { |
| 4919 | Result = getDerived().RebuildReferenceType(PointeeType, |
| 4920 | T->isSpelledAsLValue(), |
| 4921 | TL.getSigilLoc()); |
| 4922 | if (Result.isNull()) |
| 4923 | return QualType(); |
| 4924 | } |
| 4925 | |
| 4926 | // Objective-C ARC can add lifetime qualifiers to the type that we're |
| 4927 | // referring to. |
| 4928 | TLB.TypeWasModifiedSafely( |
| 4929 | Result->castAs<ReferenceType>()->getPointeeTypeAsWritten()); |
| 4930 | |
| 4931 | // r-value references can be rebuilt as l-value references. |
| 4932 | ReferenceTypeLoc NewTL; |
| 4933 | if (isa<LValueReferenceType>(Result)) |
| 4934 | NewTL = TLB.push<LValueReferenceTypeLoc>(Result); |
| 4935 | else |
| 4936 | NewTL = TLB.push<RValueReferenceTypeLoc>(Result); |
| 4937 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 4938 | |
| 4939 | return Result; |
| 4940 | } |
| 4941 | |
| 4942 | template<typename Derived> |
| 4943 | QualType |
| 4944 | TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, |
| 4945 | LValueReferenceTypeLoc TL) { |
| 4946 | return TransformReferenceType(TLB, TL); |
| 4947 | } |
| 4948 | |
| 4949 | template<typename Derived> |
| 4950 | QualType |
| 4951 | TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, |
| 4952 | RValueReferenceTypeLoc TL) { |
| 4953 | return TransformReferenceType(TLB, TL); |
| 4954 | } |
| 4955 | |
| 4956 | template<typename Derived> |
| 4957 | QualType |
| 4958 | TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, |
| 4959 | MemberPointerTypeLoc TL) { |
| 4960 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 4961 | if (PointeeType.isNull()) |
| 4962 | return QualType(); |
| 4963 | |
| 4964 | TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); |
| 4965 | TypeSourceInfo *NewClsTInfo = nullptr; |
| 4966 | if (OldClsTInfo) { |
| 4967 | NewClsTInfo = getDerived().TransformType(OldClsTInfo); |
| 4968 | if (!NewClsTInfo) |
| 4969 | return QualType(); |
| 4970 | } |
| 4971 | |
| 4972 | const MemberPointerType *T = TL.getTypePtr(); |
| 4973 | QualType OldClsType = QualType(T->getClass(), 0); |
| 4974 | QualType NewClsType; |
| 4975 | if (NewClsTInfo) |
| 4976 | NewClsType = NewClsTInfo->getType(); |
| 4977 | else { |
| 4978 | NewClsType = getDerived().TransformType(OldClsType); |
| 4979 | if (NewClsType.isNull()) |
| 4980 | return QualType(); |
| 4981 | } |
| 4982 | |
| 4983 | QualType Result = TL.getType(); |
| 4984 | if (getDerived().AlwaysRebuild() || |
| 4985 | PointeeType != T->getPointeeType() || |
| 4986 | NewClsType != OldClsType) { |
| 4987 | Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, |
| 4988 | TL.getStarLoc()); |
| 4989 | if (Result.isNull()) |
| 4990 | return QualType(); |
| 4991 | } |
| 4992 | |
| 4993 | // If we had to adjust the pointee type when building a member pointer, make |
| 4994 | // sure to push TypeLoc info for it. |
| 4995 | const MemberPointerType *MPT = Result->getAs<MemberPointerType>(); |
| 4996 | if (MPT && PointeeType != MPT->getPointeeType()) { |
| 4997 | assert(isa<AdjustedType>(MPT->getPointeeType())); |
| 4998 | TLB.push<AdjustedTypeLoc>(MPT->getPointeeType()); |
| 4999 | } |
| 5000 | |
| 5001 | MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); |
| 5002 | NewTL.setSigilLoc(TL.getSigilLoc()); |
| 5003 | NewTL.setClassTInfo(NewClsTInfo); |
| 5004 | |
| 5005 | return Result; |
| 5006 | } |
| 5007 | |
| 5008 | template<typename Derived> |
| 5009 | QualType |
| 5010 | TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, |
| 5011 | ConstantArrayTypeLoc TL) { |
| 5012 | const ConstantArrayType *T = TL.getTypePtr(); |
| 5013 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5014 | if (ElementType.isNull()) |
| 5015 | return QualType(); |
| 5016 | |
| 5017 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 5018 | Expr *OldSize = TL.getSizeExpr(); |
| 5019 | if (!OldSize) |
| 5020 | OldSize = const_cast<Expr*>(T->getSizeExpr()); |
| 5021 | Expr *NewSize = nullptr; |
| 5022 | if (OldSize) { |
| 5023 | EnterExpressionEvaluationContext Unevaluated( |
| 5024 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 5025 | NewSize = getDerived().TransformExpr(OldSize).template getAs<Expr>(); |
| 5026 | NewSize = SemaRef.ActOnConstantExpression(NewSize).get(); |
| 5027 | } |
| 5028 | |
| 5029 | QualType Result = TL.getType(); |
| 5030 | if (getDerived().AlwaysRebuild() || |
| 5031 | ElementType != T->getElementType() || |
| 5032 | (T->getSizeExpr() && NewSize != OldSize)) { |
| 5033 | Result = getDerived().RebuildConstantArrayType(ElementType, |
| 5034 | T->getSizeModifier(), |
| 5035 | T->getSize(), NewSize, |
| 5036 | T->getIndexTypeCVRQualifiers(), |
| 5037 | TL.getBracketsRange()); |
| 5038 | if (Result.isNull()) |
| 5039 | return QualType(); |
| 5040 | } |
| 5041 | |
| 5042 | // We might have either a ConstantArrayType or a VariableArrayType now: |
| 5043 | // a ConstantArrayType is allowed to have an element type which is a |
| 5044 | // VariableArrayType if the type is dependent. Fortunately, all array |
| 5045 | // types have the same location layout. |
| 5046 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 5047 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 5048 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 5049 | NewTL.setSizeExpr(NewSize); |
| 5050 | |
| 5051 | return Result; |
| 5052 | } |
| 5053 | |
| 5054 | template<typename Derived> |
| 5055 | QualType TreeTransform<Derived>::TransformIncompleteArrayType( |
| 5056 | TypeLocBuilder &TLB, |
| 5057 | IncompleteArrayTypeLoc TL) { |
| 5058 | const IncompleteArrayType *T = TL.getTypePtr(); |
| 5059 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5060 | if (ElementType.isNull()) |
| 5061 | return QualType(); |
| 5062 | |
| 5063 | QualType Result = TL.getType(); |
| 5064 | if (getDerived().AlwaysRebuild() || |
| 5065 | ElementType != T->getElementType()) { |
| 5066 | Result = getDerived().RebuildIncompleteArrayType(ElementType, |
| 5067 | T->getSizeModifier(), |
| 5068 | T->getIndexTypeCVRQualifiers(), |
| 5069 | TL.getBracketsRange()); |
| 5070 | if (Result.isNull()) |
| 5071 | return QualType(); |
| 5072 | } |
| 5073 | |
| 5074 | IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); |
| 5075 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 5076 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 5077 | NewTL.setSizeExpr(nullptr); |
| 5078 | |
| 5079 | return Result; |
| 5080 | } |
| 5081 | |
| 5082 | template<typename Derived> |
| 5083 | QualType |
| 5084 | TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, |
| 5085 | VariableArrayTypeLoc TL) { |
| 5086 | const VariableArrayType *T = TL.getTypePtr(); |
| 5087 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5088 | if (ElementType.isNull()) |
| 5089 | return QualType(); |
| 5090 | |
| 5091 | ExprResult SizeResult; |
| 5092 | { |
| 5093 | EnterExpressionEvaluationContext Context( |
| 5094 | SemaRef, Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| 5095 | SizeResult = getDerived().TransformExpr(T->getSizeExpr()); |
| 5096 | } |
| 5097 | if (SizeResult.isInvalid()) |
| 5098 | return QualType(); |
| 5099 | SizeResult = |
| 5100 | SemaRef.ActOnFinishFullExpr(SizeResult.get(), /*DiscardedValue*/ false); |
| 5101 | if (SizeResult.isInvalid()) |
| 5102 | return QualType(); |
| 5103 | |
| 5104 | Expr *Size = SizeResult.get(); |
| 5105 | |
| 5106 | QualType Result = TL.getType(); |
| 5107 | if (getDerived().AlwaysRebuild() || |
| 5108 | ElementType != T->getElementType() || |
| 5109 | Size != T->getSizeExpr()) { |
| 5110 | Result = getDerived().RebuildVariableArrayType(ElementType, |
| 5111 | T->getSizeModifier(), |
| 5112 | Size, |
| 5113 | T->getIndexTypeCVRQualifiers(), |
| 5114 | TL.getBracketsRange()); |
| 5115 | if (Result.isNull()) |
| 5116 | return QualType(); |
| 5117 | } |
| 5118 | |
| 5119 | // We might have constant size array now, but fortunately it has the same |
| 5120 | // location layout. |
| 5121 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 5122 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 5123 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 5124 | NewTL.setSizeExpr(Size); |
| 5125 | |
| 5126 | return Result; |
| 5127 | } |
| 5128 | |
| 5129 | template<typename Derived> |
| 5130 | QualType |
| 5131 | TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, |
| 5132 | DependentSizedArrayTypeLoc TL) { |
| 5133 | const DependentSizedArrayType *T = TL.getTypePtr(); |
| 5134 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5135 | if (ElementType.isNull()) |
| 5136 | return QualType(); |
| 5137 | |
| 5138 | // Array bounds are constant expressions. |
| 5139 | EnterExpressionEvaluationContext Unevaluated( |
| 5140 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 5141 | |
| 5142 | // Prefer the expression from the TypeLoc; the other may have been uniqued. |
| 5143 | Expr *origSize = TL.getSizeExpr(); |
| 5144 | if (!origSize) origSize = T->getSizeExpr(); |
| 5145 | |
| 5146 | ExprResult sizeResult |
| 5147 | = getDerived().TransformExpr(origSize); |
| 5148 | sizeResult = SemaRef.ActOnConstantExpression(sizeResult); |
| 5149 | if (sizeResult.isInvalid()) |
| 5150 | return QualType(); |
| 5151 | |
| 5152 | Expr *size = sizeResult.get(); |
| 5153 | |
| 5154 | QualType Result = TL.getType(); |
| 5155 | if (getDerived().AlwaysRebuild() || |
| 5156 | ElementType != T->getElementType() || |
| 5157 | size != origSize) { |
| 5158 | Result = getDerived().RebuildDependentSizedArrayType(ElementType, |
| 5159 | T->getSizeModifier(), |
| 5160 | size, |
| 5161 | T->getIndexTypeCVRQualifiers(), |
| 5162 | TL.getBracketsRange()); |
| 5163 | if (Result.isNull()) |
| 5164 | return QualType(); |
| 5165 | } |
| 5166 | |
| 5167 | // We might have any sort of array type now, but fortunately they |
| 5168 | // all have the same location layout. |
| 5169 | ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); |
| 5170 | NewTL.setLBracketLoc(TL.getLBracketLoc()); |
| 5171 | NewTL.setRBracketLoc(TL.getRBracketLoc()); |
| 5172 | NewTL.setSizeExpr(size); |
| 5173 | |
| 5174 | return Result; |
| 5175 | } |
| 5176 | |
| 5177 | template <typename Derived> |
| 5178 | QualType TreeTransform<Derived>::TransformDependentVectorType( |
| 5179 | TypeLocBuilder &TLB, DependentVectorTypeLoc TL) { |
| 5180 | const DependentVectorType *T = TL.getTypePtr(); |
| 5181 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5182 | if (ElementType.isNull()) |
| 5183 | return QualType(); |
| 5184 | |
| 5185 | EnterExpressionEvaluationContext Unevaluated( |
| 5186 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 5187 | |
| 5188 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 5189 | Size = SemaRef.ActOnConstantExpression(Size); |
| 5190 | if (Size.isInvalid()) |
| 5191 | return QualType(); |
| 5192 | |
| 5193 | QualType Result = TL.getType(); |
| 5194 | if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() || |
| 5195 | Size.get() != T->getSizeExpr()) { |
| 5196 | Result = getDerived().RebuildDependentVectorType( |
| 5197 | ElementType, Size.get(), T->getAttributeLoc(), T->getVectorKind()); |
| 5198 | if (Result.isNull()) |
| 5199 | return QualType(); |
| 5200 | } |
| 5201 | |
| 5202 | // Result might be dependent or not. |
| 5203 | if (isa<DependentVectorType>(Result)) { |
| 5204 | DependentVectorTypeLoc NewTL = |
| 5205 | TLB.push<DependentVectorTypeLoc>(Result); |
| 5206 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5207 | } else { |
| 5208 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 5209 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5210 | } |
| 5211 | |
| 5212 | return Result; |
| 5213 | } |
| 5214 | |
| 5215 | template<typename Derived> |
| 5216 | QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( |
| 5217 | TypeLocBuilder &TLB, |
| 5218 | DependentSizedExtVectorTypeLoc TL) { |
| 5219 | const DependentSizedExtVectorType *T = TL.getTypePtr(); |
| 5220 | |
| 5221 | // FIXME: ext vector locs should be nested |
| 5222 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5223 | if (ElementType.isNull()) |
| 5224 | return QualType(); |
| 5225 | |
| 5226 | // Vector sizes are constant expressions. |
| 5227 | EnterExpressionEvaluationContext Unevaluated( |
| 5228 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 5229 | |
| 5230 | ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); |
| 5231 | Size = SemaRef.ActOnConstantExpression(Size); |
| 5232 | if (Size.isInvalid()) |
| 5233 | return QualType(); |
| 5234 | |
| 5235 | QualType Result = TL.getType(); |
| 5236 | if (getDerived().AlwaysRebuild() || |
| 5237 | ElementType != T->getElementType() || |
| 5238 | Size.get() != T->getSizeExpr()) { |
| 5239 | Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, |
| 5240 | Size.get(), |
| 5241 | T->getAttributeLoc()); |
| 5242 | if (Result.isNull()) |
| 5243 | return QualType(); |
| 5244 | } |
| 5245 | |
| 5246 | // Result might be dependent or not. |
| 5247 | if (isa<DependentSizedExtVectorType>(Result)) { |
| 5248 | DependentSizedExtVectorTypeLoc NewTL |
| 5249 | = TLB.push<DependentSizedExtVectorTypeLoc>(Result); |
| 5250 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5251 | } else { |
| 5252 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 5253 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5254 | } |
| 5255 | |
| 5256 | return Result; |
| 5257 | } |
| 5258 | |
| 5259 | template <typename Derived> |
| 5260 | QualType |
| 5261 | TreeTransform<Derived>::TransformConstantMatrixType(TypeLocBuilder &TLB, |
| 5262 | ConstantMatrixTypeLoc TL) { |
| 5263 | const ConstantMatrixType *T = TL.getTypePtr(); |
| 5264 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 5265 | if (ElementType.isNull()) |
| 5266 | return QualType(); |
| 5267 | |
| 5268 | QualType Result = TL.getType(); |
| 5269 | if (getDerived().AlwaysRebuild() || ElementType != T->getElementType()) { |
| 5270 | Result = getDerived().RebuildConstantMatrixType( |
| 5271 | ElementType, T->getNumRows(), T->getNumColumns()); |
| 5272 | if (Result.isNull()) |
| 5273 | return QualType(); |
| 5274 | } |
| 5275 | |
| 5276 | ConstantMatrixTypeLoc NewTL = TLB.push<ConstantMatrixTypeLoc>(Result); |
| 5277 | NewTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5278 | NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5279 | NewTL.setAttrRowOperand(TL.getAttrRowOperand()); |
| 5280 | NewTL.setAttrColumnOperand(TL.getAttrColumnOperand()); |
| 5281 | |
| 5282 | return Result; |
| 5283 | } |
| 5284 | |
| 5285 | template <typename Derived> |
| 5286 | QualType TreeTransform<Derived>::TransformDependentSizedMatrixType( |
| 5287 | TypeLocBuilder &TLB, DependentSizedMatrixTypeLoc TL) { |
| 5288 | const DependentSizedMatrixType *T = TL.getTypePtr(); |
| 5289 | |
| 5290 | QualType ElementType = getDerived().TransformType(T->getElementType()); |
| 5291 | if (ElementType.isNull()) { |
| 5292 | return QualType(); |
| 5293 | } |
| 5294 | |
| 5295 | // Matrix dimensions are constant expressions. |
| 5296 | EnterExpressionEvaluationContext Unevaluated( |
| 5297 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 5298 | |
| 5299 | Expr *origRows = TL.getAttrRowOperand(); |
| 5300 | if (!origRows) |
| 5301 | origRows = T->getRowExpr(); |
| 5302 | Expr *origColumns = TL.getAttrColumnOperand(); |
| 5303 | if (!origColumns) |
| 5304 | origColumns = T->getColumnExpr(); |
| 5305 | |
| 5306 | ExprResult rowResult = getDerived().TransformExpr(origRows); |
| 5307 | rowResult = SemaRef.ActOnConstantExpression(rowResult); |
| 5308 | if (rowResult.isInvalid()) |
| 5309 | return QualType(); |
| 5310 | |
| 5311 | ExprResult columnResult = getDerived().TransformExpr(origColumns); |
| 5312 | columnResult = SemaRef.ActOnConstantExpression(columnResult); |
| 5313 | if (columnResult.isInvalid()) |
| 5314 | return QualType(); |
| 5315 | |
| 5316 | Expr *rows = rowResult.get(); |
| 5317 | Expr *columns = columnResult.get(); |
| 5318 | |
| 5319 | QualType Result = TL.getType(); |
| 5320 | if (getDerived().AlwaysRebuild() || ElementType != T->getElementType() || |
| 5321 | rows != origRows || columns != origColumns) { |
| 5322 | Result = getDerived().RebuildDependentSizedMatrixType( |
| 5323 | ElementType, rows, columns, T->getAttributeLoc()); |
| 5324 | |
| 5325 | if (Result.isNull()) |
| 5326 | return QualType(); |
| 5327 | } |
| 5328 | |
| 5329 | // We might have any sort of matrix type now, but fortunately they |
| 5330 | // all have the same location layout. |
| 5331 | MatrixTypeLoc NewTL = TLB.push<MatrixTypeLoc>(Result); |
| 5332 | NewTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5333 | NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5334 | NewTL.setAttrRowOperand(rows); |
| 5335 | NewTL.setAttrColumnOperand(columns); |
| 5336 | return Result; |
| 5337 | } |
| 5338 | |
| 5339 | template <typename Derived> |
| 5340 | QualType TreeTransform<Derived>::TransformDependentAddressSpaceType( |
| 5341 | TypeLocBuilder &TLB, DependentAddressSpaceTypeLoc TL) { |
| 5342 | const DependentAddressSpaceType *T = TL.getTypePtr(); |
| 5343 | |
| 5344 | QualType pointeeType = getDerived().TransformType(T->getPointeeType()); |
| 5345 | |
| 5346 | if (pointeeType.isNull()) |
| 5347 | return QualType(); |
| 5348 | |
| 5349 | // Address spaces are constant expressions. |
| 5350 | EnterExpressionEvaluationContext Unevaluated( |
| 5351 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 5352 | |
| 5353 | ExprResult AddrSpace = getDerived().TransformExpr(T->getAddrSpaceExpr()); |
| 5354 | AddrSpace = SemaRef.ActOnConstantExpression(AddrSpace); |
| 5355 | if (AddrSpace.isInvalid()) |
| 5356 | return QualType(); |
| 5357 | |
| 5358 | QualType Result = TL.getType(); |
| 5359 | if (getDerived().AlwaysRebuild() || pointeeType != T->getPointeeType() || |
| 5360 | AddrSpace.get() != T->getAddrSpaceExpr()) { |
| 5361 | Result = getDerived().RebuildDependentAddressSpaceType( |
| 5362 | pointeeType, AddrSpace.get(), T->getAttributeLoc()); |
| 5363 | if (Result.isNull()) |
| 5364 | return QualType(); |
| 5365 | } |
| 5366 | |
| 5367 | // Result might be dependent or not. |
| 5368 | if (isa<DependentAddressSpaceType>(Result)) { |
| 5369 | DependentAddressSpaceTypeLoc NewTL = |
| 5370 | TLB.push<DependentAddressSpaceTypeLoc>(Result); |
| 5371 | |
| 5372 | NewTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); |
| 5373 | NewTL.setAttrExprOperand(TL.getAttrExprOperand()); |
| 5374 | NewTL.setAttrNameLoc(TL.getAttrNameLoc()); |
| 5375 | |
| 5376 | } else { |
| 5377 | TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo( |
| 5378 | Result, getDerived().getBaseLocation()); |
| 5379 | TransformType(TLB, DI->getTypeLoc()); |
| 5380 | } |
| 5381 | |
| 5382 | return Result; |
| 5383 | } |
| 5384 | |
| 5385 | template <typename Derived> |
| 5386 | QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, |
| 5387 | VectorTypeLoc TL) { |
| 5388 | const VectorType *T = TL.getTypePtr(); |
| 5389 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5390 | if (ElementType.isNull()) |
| 5391 | return QualType(); |
| 5392 | |
| 5393 | QualType Result = TL.getType(); |
| 5394 | if (getDerived().AlwaysRebuild() || |
| 5395 | ElementType != T->getElementType()) { |
| 5396 | Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), |
| 5397 | T->getVectorKind()); |
| 5398 | if (Result.isNull()) |
| 5399 | return QualType(); |
| 5400 | } |
| 5401 | |
| 5402 | VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); |
| 5403 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5404 | |
| 5405 | return Result; |
| 5406 | } |
| 5407 | |
| 5408 | template<typename Derived> |
| 5409 | QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, |
| 5410 | ExtVectorTypeLoc TL) { |
| 5411 | const VectorType *T = TL.getTypePtr(); |
| 5412 | QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); |
| 5413 | if (ElementType.isNull()) |
| 5414 | return QualType(); |
| 5415 | |
| 5416 | QualType Result = TL.getType(); |
| 5417 | if (getDerived().AlwaysRebuild() || |
| 5418 | ElementType != T->getElementType()) { |
| 5419 | Result = getDerived().RebuildExtVectorType(ElementType, |
| 5420 | T->getNumElements(), |
| 5421 | /*FIXME*/ SourceLocation()); |
| 5422 | if (Result.isNull()) |
| 5423 | return QualType(); |
| 5424 | } |
| 5425 | |
| 5426 | ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); |
| 5427 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5428 | |
| 5429 | return Result; |
| 5430 | } |
| 5431 | |
| 5432 | template <typename Derived> |
| 5433 | ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam( |
| 5434 | ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions, |
| 5435 | bool ExpectParameterPack) { |
| 5436 | TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); |
| 5437 | TypeSourceInfo *NewDI = nullptr; |
| 5438 | |
| 5439 | if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { |
| 5440 | // If we're substituting into a pack expansion type and we know the |
| 5441 | // length we want to expand to, just substitute for the pattern. |
| 5442 | TypeLoc OldTL = OldDI->getTypeLoc(); |
| 5443 | PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>(); |
| 5444 | |
| 5445 | TypeLocBuilder TLB; |
| 5446 | TypeLoc NewTL = OldDI->getTypeLoc(); |
| 5447 | TLB.reserve(NewTL.getFullDataSize()); |
| 5448 | |
| 5449 | QualType Result = getDerived().TransformType(TLB, |
| 5450 | OldExpansionTL.getPatternLoc()); |
| 5451 | if (Result.isNull()) |
| 5452 | return nullptr; |
| 5453 | |
| 5454 | Result = RebuildPackExpansionType(Result, |
| 5455 | OldExpansionTL.getPatternLoc().getSourceRange(), |
| 5456 | OldExpansionTL.getEllipsisLoc(), |
| 5457 | NumExpansions); |
| 5458 | if (Result.isNull()) |
| 5459 | return nullptr; |
| 5460 | |
| 5461 | PackExpansionTypeLoc NewExpansionTL |
| 5462 | = TLB.push<PackExpansionTypeLoc>(Result); |
| 5463 | NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); |
| 5464 | NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); |
| 5465 | } else |
| 5466 | NewDI = getDerived().TransformType(OldDI); |
| 5467 | if (!NewDI) |
| 5468 | return nullptr; |
| 5469 | |
| 5470 | if (NewDI == OldDI && indexAdjustment == 0) |
| 5471 | return OldParm; |
| 5472 | |
| 5473 | ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, |
| 5474 | OldParm->getDeclContext(), |
| 5475 | OldParm->getInnerLocStart(), |
| 5476 | OldParm->getLocation(), |
| 5477 | OldParm->getIdentifier(), |
| 5478 | NewDI->getType(), |
| 5479 | NewDI, |
| 5480 | OldParm->getStorageClass(), |
| 5481 | /* DefArg */ nullptr); |
| 5482 | newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), |
| 5483 | OldParm->getFunctionScopeIndex() + indexAdjustment); |
| 5484 | transformedLocalDecl(OldParm, {newParm}); |
| 5485 | return newParm; |
| 5486 | } |
| 5487 | |
| 5488 | template <typename Derived> |
| 5489 | bool TreeTransform<Derived>::TransformFunctionTypeParams( |
| 5490 | SourceLocation Loc, ArrayRef<ParmVarDecl *> Params, |
| 5491 | const QualType *ParamTypes, |
| 5492 | const FunctionProtoType::ExtParameterInfo *ParamInfos, |
| 5493 | SmallVectorImpl<QualType> &OutParamTypes, |
| 5494 | SmallVectorImpl<ParmVarDecl *> *PVars, |
| 5495 | Sema::ExtParameterInfoBuilder &PInfos) { |
| 5496 | int indexAdjustment = 0; |
| 5497 | |
| 5498 | unsigned NumParams = Params.size(); |
| 5499 | for (unsigned i = 0; i != NumParams; ++i) { |
| 5500 | if (ParmVarDecl *OldParm = Params[i]) { |
| 5501 | assert(OldParm->getFunctionScopeIndex() == i); |
| 5502 | |
| 5503 | Optional<unsigned> NumExpansions; |
| 5504 | ParmVarDecl *NewParm = nullptr; |
| 5505 | if (OldParm->isParameterPack()) { |
| 5506 | // We have a function parameter pack that may need to be expanded. |
| 5507 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5508 | |
| 5509 | // Find the parameter packs that could be expanded. |
| 5510 | TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); |
| 5511 | PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>(); |
| 5512 | TypeLoc Pattern = ExpansionTL.getPatternLoc(); |
| 5513 | SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 5514 | |
| 5515 | // Determine whether we should expand the parameter packs. |
| 5516 | bool ShouldExpand = false; |
| 5517 | bool RetainExpansion = false; |
| 5518 | Optional<unsigned> OrigNumExpansions; |
| 5519 | if (Unexpanded.size() > 0) { |
| 5520 | OrigNumExpansions = ExpansionTL.getTypePtr()->getNumExpansions(); |
| 5521 | NumExpansions = OrigNumExpansions; |
| 5522 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 5523 | Pattern.getSourceRange(), |
| 5524 | Unexpanded, |
| 5525 | ShouldExpand, |
| 5526 | RetainExpansion, |
| 5527 | NumExpansions)) { |
| 5528 | return true; |
| 5529 | } |
| 5530 | } else { |
| 5531 | #ifndef NDEBUG |
| 5532 | const AutoType *AT = |
| 5533 | Pattern.getType().getTypePtr()->getContainedAutoType(); |
| 5534 | assert((AT && (!AT->isDeduced() || AT->getDeducedType().isNull())) && |
| 5535 | "Could not find parameter packs or undeduced auto type!" ); |
| 5536 | #endif |
| 5537 | } |
| 5538 | |
| 5539 | if (ShouldExpand) { |
| 5540 | // Expand the function parameter pack into multiple, separate |
| 5541 | // parameters. |
| 5542 | getDerived().ExpandingFunctionParameterPack(OldParm); |
| 5543 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 5544 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 5545 | ParmVarDecl *NewParm |
| 5546 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 5547 | indexAdjustment++, |
| 5548 | OrigNumExpansions, |
| 5549 | /*ExpectParameterPack=*/false); |
| 5550 | if (!NewParm) |
| 5551 | return true; |
| 5552 | |
| 5553 | if (ParamInfos) |
| 5554 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 5555 | OutParamTypes.push_back(NewParm->getType()); |
| 5556 | if (PVars) |
| 5557 | PVars->push_back(NewParm); |
| 5558 | } |
| 5559 | |
| 5560 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 5561 | // forgetting the partially-substituted parameter pack. |
| 5562 | if (RetainExpansion) { |
| 5563 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 5564 | ParmVarDecl *NewParm |
| 5565 | = getDerived().TransformFunctionTypeParam(OldParm, |
| 5566 | indexAdjustment++, |
| 5567 | OrigNumExpansions, |
| 5568 | /*ExpectParameterPack=*/false); |
| 5569 | if (!NewParm) |
| 5570 | return true; |
| 5571 | |
| 5572 | if (ParamInfos) |
| 5573 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 5574 | OutParamTypes.push_back(NewParm->getType()); |
| 5575 | if (PVars) |
| 5576 | PVars->push_back(NewParm); |
| 5577 | } |
| 5578 | |
| 5579 | // The next parameter should have the same adjustment as the |
| 5580 | // last thing we pushed, but we post-incremented indexAdjustment |
| 5581 | // on every push. Also, if we push nothing, the adjustment should |
| 5582 | // go down by one. |
| 5583 | indexAdjustment--; |
| 5584 | |
| 5585 | // We're done with the pack expansion. |
| 5586 | continue; |
| 5587 | } |
| 5588 | |
| 5589 | // We'll substitute the parameter now without expanding the pack |
| 5590 | // expansion. |
| 5591 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5592 | NewParm = getDerived().TransformFunctionTypeParam(OldParm, |
| 5593 | indexAdjustment, |
| 5594 | NumExpansions, |
| 5595 | /*ExpectParameterPack=*/true); |
| 5596 | assert(NewParm->isParameterPack() && |
| 5597 | "Parameter pack no longer a parameter pack after " |
| 5598 | "transformation." ); |
| 5599 | } else { |
| 5600 | NewParm = getDerived().TransformFunctionTypeParam( |
| 5601 | OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false); |
| 5602 | } |
| 5603 | |
| 5604 | if (!NewParm) |
| 5605 | return true; |
| 5606 | |
| 5607 | if (ParamInfos) |
| 5608 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 5609 | OutParamTypes.push_back(NewParm->getType()); |
| 5610 | if (PVars) |
| 5611 | PVars->push_back(NewParm); |
| 5612 | continue; |
| 5613 | } |
| 5614 | |
| 5615 | // Deal with the possibility that we don't have a parameter |
| 5616 | // declaration for this parameter. |
| 5617 | QualType OldType = ParamTypes[i]; |
| 5618 | bool IsPackExpansion = false; |
| 5619 | Optional<unsigned> NumExpansions; |
| 5620 | QualType NewType; |
| 5621 | if (const PackExpansionType *Expansion |
| 5622 | = dyn_cast<PackExpansionType>(OldType)) { |
| 5623 | // We have a function parameter pack that may need to be expanded. |
| 5624 | QualType Pattern = Expansion->getPattern(); |
| 5625 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5626 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 5627 | |
| 5628 | // Determine whether we should expand the parameter packs. |
| 5629 | bool ShouldExpand = false; |
| 5630 | bool RetainExpansion = false; |
| 5631 | if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), |
| 5632 | Unexpanded, |
| 5633 | ShouldExpand, |
| 5634 | RetainExpansion, |
| 5635 | NumExpansions)) { |
| 5636 | return true; |
| 5637 | } |
| 5638 | |
| 5639 | if (ShouldExpand) { |
| 5640 | // Expand the function parameter pack into multiple, separate |
| 5641 | // parameters. |
| 5642 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 5643 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 5644 | QualType NewType = getDerived().TransformType(Pattern); |
| 5645 | if (NewType.isNull()) |
| 5646 | return true; |
| 5647 | |
| 5648 | if (NewType->containsUnexpandedParameterPack()) { |
| 5649 | NewType = |
| 5650 | getSema().getASTContext().getPackExpansionType(NewType, None); |
| 5651 | |
| 5652 | if (NewType.isNull()) |
| 5653 | return true; |
| 5654 | } |
| 5655 | |
| 5656 | if (ParamInfos) |
| 5657 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 5658 | OutParamTypes.push_back(NewType); |
| 5659 | if (PVars) |
| 5660 | PVars->push_back(nullptr); |
| 5661 | } |
| 5662 | |
| 5663 | // We're done with the pack expansion. |
| 5664 | continue; |
| 5665 | } |
| 5666 | |
| 5667 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 5668 | // forgetting the partially-substituted parameter pack. |
| 5669 | if (RetainExpansion) { |
| 5670 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 5671 | QualType NewType = getDerived().TransformType(Pattern); |
| 5672 | if (NewType.isNull()) |
| 5673 | return true; |
| 5674 | |
| 5675 | if (ParamInfos) |
| 5676 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 5677 | OutParamTypes.push_back(NewType); |
| 5678 | if (PVars) |
| 5679 | PVars->push_back(nullptr); |
| 5680 | } |
| 5681 | |
| 5682 | // We'll substitute the parameter now without expanding the pack |
| 5683 | // expansion. |
| 5684 | OldType = Expansion->getPattern(); |
| 5685 | IsPackExpansion = true; |
| 5686 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5687 | NewType = getDerived().TransformType(OldType); |
| 5688 | } else { |
| 5689 | NewType = getDerived().TransformType(OldType); |
| 5690 | } |
| 5691 | |
| 5692 | if (NewType.isNull()) |
| 5693 | return true; |
| 5694 | |
| 5695 | if (IsPackExpansion) |
| 5696 | NewType = getSema().Context.getPackExpansionType(NewType, |
| 5697 | NumExpansions); |
| 5698 | |
| 5699 | if (ParamInfos) |
| 5700 | PInfos.set(OutParamTypes.size(), ParamInfos[i]); |
| 5701 | OutParamTypes.push_back(NewType); |
| 5702 | if (PVars) |
| 5703 | PVars->push_back(nullptr); |
| 5704 | } |
| 5705 | |
| 5706 | #ifndef NDEBUG |
| 5707 | if (PVars) { |
| 5708 | for (unsigned i = 0, e = PVars->size(); i != e; ++i) |
| 5709 | if (ParmVarDecl *parm = (*PVars)[i]) |
| 5710 | assert(parm->getFunctionScopeIndex() == i); |
| 5711 | } |
| 5712 | #endif |
| 5713 | |
| 5714 | return false; |
| 5715 | } |
| 5716 | |
| 5717 | template<typename Derived> |
| 5718 | QualType |
| 5719 | TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, |
| 5720 | FunctionProtoTypeLoc TL) { |
| 5721 | SmallVector<QualType, 4> ExceptionStorage; |
| 5722 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
| 5723 | return getDerived().TransformFunctionProtoType( |
| 5724 | TLB, TL, nullptr, Qualifiers(), |
| 5725 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 5726 | return This->TransformExceptionSpec(TL.getBeginLoc(), ESI, |
| 5727 | ExceptionStorage, Changed); |
| 5728 | }); |
| 5729 | } |
| 5730 | |
| 5731 | template<typename Derived> template<typename Fn> |
| 5732 | QualType TreeTransform<Derived>::TransformFunctionProtoType( |
| 5733 | TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext, |
| 5734 | Qualifiers ThisTypeQuals, Fn TransformExceptionSpec) { |
| 5735 | |
| 5736 | // Transform the parameters and return type. |
| 5737 | // |
| 5738 | // We are required to instantiate the params and return type in source order. |
| 5739 | // When the function has a trailing return type, we instantiate the |
| 5740 | // parameters before the return type, since the return type can then refer |
| 5741 | // to the parameters themselves (via decltype, sizeof, etc.). |
| 5742 | // |
| 5743 | SmallVector<QualType, 4> ParamTypes; |
| 5744 | SmallVector<ParmVarDecl*, 4> ParamDecls; |
| 5745 | Sema::ExtParameterInfoBuilder ExtParamInfos; |
| 5746 | const FunctionProtoType *T = TL.getTypePtr(); |
| 5747 | |
| 5748 | QualType ResultType; |
| 5749 | |
| 5750 | if (T->hasTrailingReturn()) { |
| 5751 | if (getDerived().TransformFunctionTypeParams( |
| 5752 | TL.getBeginLoc(), TL.getParams(), |
| 5753 | TL.getTypePtr()->param_type_begin(), |
| 5754 | T->getExtParameterInfosOrNull(), |
| 5755 | ParamTypes, &ParamDecls, ExtParamInfos)) |
| 5756 | return QualType(); |
| 5757 | |
| 5758 | { |
| 5759 | // C++11 [expr.prim.general]p3: |
| 5760 | // If a declaration declares a member function or member function |
| 5761 | // template of a class X, the expression this is a prvalue of type |
| 5762 | // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq |
| 5763 | // and the end of the function-definition, member-declarator, or |
| 5764 | // declarator. |
| 5765 | Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); |
| 5766 | |
| 5767 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| 5768 | if (ResultType.isNull()) |
| 5769 | return QualType(); |
| 5770 | } |
| 5771 | } |
| 5772 | else { |
| 5773 | ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| 5774 | if (ResultType.isNull()) |
| 5775 | return QualType(); |
| 5776 | |
| 5777 | if (getDerived().TransformFunctionTypeParams( |
| 5778 | TL.getBeginLoc(), TL.getParams(), |
| 5779 | TL.getTypePtr()->param_type_begin(), |
| 5780 | T->getExtParameterInfosOrNull(), |
| 5781 | ParamTypes, &ParamDecls, ExtParamInfos)) |
| 5782 | return QualType(); |
| 5783 | } |
| 5784 | |
| 5785 | FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo(); |
| 5786 | |
| 5787 | bool EPIChanged = false; |
| 5788 | if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged)) |
| 5789 | return QualType(); |
| 5790 | |
| 5791 | // Handle extended parameter information. |
| 5792 | if (auto NewExtParamInfos = |
| 5793 | ExtParamInfos.getPointerOrNull(ParamTypes.size())) { |
| 5794 | if (!EPI.ExtParameterInfos || |
| 5795 | llvm::makeArrayRef(EPI.ExtParameterInfos, TL.getNumParams()) |
| 5796 | != llvm::makeArrayRef(NewExtParamInfos, ParamTypes.size())) { |
| 5797 | EPIChanged = true; |
| 5798 | } |
| 5799 | EPI.ExtParameterInfos = NewExtParamInfos; |
| 5800 | } else if (EPI.ExtParameterInfos) { |
| 5801 | EPIChanged = true; |
| 5802 | EPI.ExtParameterInfos = nullptr; |
| 5803 | } |
| 5804 | |
| 5805 | QualType Result = TL.getType(); |
| 5806 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() || |
| 5807 | T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) { |
| 5808 | Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI); |
| 5809 | if (Result.isNull()) |
| 5810 | return QualType(); |
| 5811 | } |
| 5812 | |
| 5813 | FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); |
| 5814 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 5815 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5816 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5817 | NewTL.setExceptionSpecRange(TL.getExceptionSpecRange()); |
| 5818 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
| 5819 | for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i) |
| 5820 | NewTL.setParam(i, ParamDecls[i]); |
| 5821 | |
| 5822 | return Result; |
| 5823 | } |
| 5824 | |
| 5825 | template<typename Derived> |
| 5826 | bool TreeTransform<Derived>::TransformExceptionSpec( |
| 5827 | SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI, |
| 5828 | SmallVectorImpl<QualType> &Exceptions, bool &Changed) { |
| 5829 | assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated); |
| 5830 | |
| 5831 | // Instantiate a dynamic noexcept expression, if any. |
| 5832 | if (isComputedNoexcept(ESI.Type)) { |
| 5833 | EnterExpressionEvaluationContext Unevaluated( |
| 5834 | getSema(), Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 5835 | ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr); |
| 5836 | if (NoexceptExpr.isInvalid()) |
| 5837 | return true; |
| 5838 | |
| 5839 | ExceptionSpecificationType EST = ESI.Type; |
| 5840 | NoexceptExpr = |
| 5841 | getSema().ActOnNoexceptSpec(Loc, NoexceptExpr.get(), EST); |
| 5842 | if (NoexceptExpr.isInvalid()) |
| 5843 | return true; |
| 5844 | |
| 5845 | if (ESI.NoexceptExpr != NoexceptExpr.get() || EST != ESI.Type) |
| 5846 | Changed = true; |
| 5847 | ESI.NoexceptExpr = NoexceptExpr.get(); |
| 5848 | ESI.Type = EST; |
| 5849 | } |
| 5850 | |
| 5851 | if (ESI.Type != EST_Dynamic) |
| 5852 | return false; |
| 5853 | |
| 5854 | // Instantiate a dynamic exception specification's type. |
| 5855 | for (QualType T : ESI.Exceptions) { |
| 5856 | if (const PackExpansionType *PackExpansion = |
| 5857 | T->getAs<PackExpansionType>()) { |
| 5858 | Changed = true; |
| 5859 | |
| 5860 | // We have a pack expansion. Instantiate it. |
| 5861 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 5862 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 5863 | Unexpanded); |
| 5864 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?" ); |
| 5865 | |
| 5866 | // Determine whether the set of unexpanded parameter packs can and |
| 5867 | // should |
| 5868 | // be expanded. |
| 5869 | bool Expand = false; |
| 5870 | bool RetainExpansion = false; |
| 5871 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 5872 | // FIXME: Track the location of the ellipsis (and track source location |
| 5873 | // information for the types in the exception specification in general). |
| 5874 | if (getDerived().TryExpandParameterPacks( |
| 5875 | Loc, SourceRange(), Unexpanded, Expand, |
| 5876 | RetainExpansion, NumExpansions)) |
| 5877 | return true; |
| 5878 | |
| 5879 | if (!Expand) { |
| 5880 | // We can't expand this pack expansion into separate arguments yet; |
| 5881 | // just substitute into the pattern and create a new pack expansion |
| 5882 | // type. |
| 5883 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 5884 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 5885 | if (U.isNull()) |
| 5886 | return true; |
| 5887 | |
| 5888 | U = SemaRef.Context.getPackExpansionType(U, NumExpansions); |
| 5889 | Exceptions.push_back(U); |
| 5890 | continue; |
| 5891 | } |
| 5892 | |
| 5893 | // Substitute into the pack expansion pattern for each slice of the |
| 5894 | // pack. |
| 5895 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 5896 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 5897 | |
| 5898 | QualType U = getDerived().TransformType(PackExpansion->getPattern()); |
| 5899 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 5900 | return true; |
| 5901 | |
| 5902 | Exceptions.push_back(U); |
| 5903 | } |
| 5904 | } else { |
| 5905 | QualType U = getDerived().TransformType(T); |
| 5906 | if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc)) |
| 5907 | return true; |
| 5908 | if (T != U) |
| 5909 | Changed = true; |
| 5910 | |
| 5911 | Exceptions.push_back(U); |
| 5912 | } |
| 5913 | } |
| 5914 | |
| 5915 | ESI.Exceptions = Exceptions; |
| 5916 | if (ESI.Exceptions.empty()) |
| 5917 | ESI.Type = EST_DynamicNone; |
| 5918 | return false; |
| 5919 | } |
| 5920 | |
| 5921 | template<typename Derived> |
| 5922 | QualType TreeTransform<Derived>::TransformFunctionNoProtoType( |
| 5923 | TypeLocBuilder &TLB, |
| 5924 | FunctionNoProtoTypeLoc TL) { |
| 5925 | const FunctionNoProtoType *T = TL.getTypePtr(); |
| 5926 | QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc()); |
| 5927 | if (ResultType.isNull()) |
| 5928 | return QualType(); |
| 5929 | |
| 5930 | QualType Result = TL.getType(); |
| 5931 | if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType()) |
| 5932 | Result = getDerived().RebuildFunctionNoProtoType(ResultType); |
| 5933 | |
| 5934 | FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); |
| 5935 | NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); |
| 5936 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 5937 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 5938 | NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); |
| 5939 | |
| 5940 | return Result; |
| 5941 | } |
| 5942 | |
| 5943 | template<typename Derived> QualType |
| 5944 | TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, |
| 5945 | UnresolvedUsingTypeLoc TL) { |
| 5946 | const UnresolvedUsingType *T = TL.getTypePtr(); |
| 5947 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); |
| 5948 | if (!D) |
| 5949 | return QualType(); |
| 5950 | |
| 5951 | QualType Result = TL.getType(); |
| 5952 | if (getDerived().AlwaysRebuild() || D != T->getDecl()) { |
| 5953 | Result = getDerived().RebuildUnresolvedUsingType(TL.getNameLoc(), D); |
| 5954 | if (Result.isNull()) |
| 5955 | return QualType(); |
| 5956 | } |
| 5957 | |
| 5958 | // We might get an arbitrary type spec type back. We should at |
| 5959 | // least always get a type spec type, though. |
| 5960 | TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); |
| 5961 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5962 | |
| 5963 | return Result; |
| 5964 | } |
| 5965 | |
| 5966 | template<typename Derived> |
| 5967 | QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, |
| 5968 | TypedefTypeLoc TL) { |
| 5969 | const TypedefType *T = TL.getTypePtr(); |
| 5970 | TypedefNameDecl *Typedef |
| 5971 | = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 5972 | T->getDecl())); |
| 5973 | if (!Typedef) |
| 5974 | return QualType(); |
| 5975 | |
| 5976 | QualType Result = TL.getType(); |
| 5977 | if (getDerived().AlwaysRebuild() || |
| 5978 | Typedef != T->getDecl()) { |
| 5979 | Result = getDerived().RebuildTypedefType(Typedef); |
| 5980 | if (Result.isNull()) |
| 5981 | return QualType(); |
| 5982 | } |
| 5983 | |
| 5984 | TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); |
| 5985 | NewTL.setNameLoc(TL.getNameLoc()); |
| 5986 | |
| 5987 | return Result; |
| 5988 | } |
| 5989 | |
| 5990 | template<typename Derived> |
| 5991 | QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, |
| 5992 | TypeOfExprTypeLoc TL) { |
| 5993 | // typeof expressions are not potentially evaluated contexts |
| 5994 | EnterExpressionEvaluationContext Unevaluated( |
| 5995 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 5996 | Sema::ReuseLambdaContextDecl); |
| 5997 | |
| 5998 | ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); |
| 5999 | if (E.isInvalid()) |
| 6000 | return QualType(); |
| 6001 | |
| 6002 | E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); |
| 6003 | if (E.isInvalid()) |
| 6004 | return QualType(); |
| 6005 | |
| 6006 | QualType Result = TL.getType(); |
| 6007 | if (getDerived().AlwaysRebuild() || |
| 6008 | E.get() != TL.getUnderlyingExpr()) { |
| 6009 | Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); |
| 6010 | if (Result.isNull()) |
| 6011 | return QualType(); |
| 6012 | } |
| 6013 | else E.get(); |
| 6014 | |
| 6015 | TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); |
| 6016 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 6017 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 6018 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 6019 | |
| 6020 | return Result; |
| 6021 | } |
| 6022 | |
| 6023 | template<typename Derived> |
| 6024 | QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, |
| 6025 | TypeOfTypeLoc TL) { |
| 6026 | TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); |
| 6027 | TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); |
| 6028 | if (!New_Under_TI) |
| 6029 | return QualType(); |
| 6030 | |
| 6031 | QualType Result = TL.getType(); |
| 6032 | if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { |
| 6033 | Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); |
| 6034 | if (Result.isNull()) |
| 6035 | return QualType(); |
| 6036 | } |
| 6037 | |
| 6038 | TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); |
| 6039 | NewTL.setTypeofLoc(TL.getTypeofLoc()); |
| 6040 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 6041 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 6042 | NewTL.setUnderlyingTInfo(New_Under_TI); |
| 6043 | |
| 6044 | return Result; |
| 6045 | } |
| 6046 | |
| 6047 | template<typename Derived> |
| 6048 | QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, |
| 6049 | DecltypeTypeLoc TL) { |
| 6050 | const DecltypeType *T = TL.getTypePtr(); |
| 6051 | |
| 6052 | // decltype expressions are not potentially evaluated contexts |
| 6053 | EnterExpressionEvaluationContext Unevaluated( |
| 6054 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, nullptr, |
| 6055 | Sema::ExpressionEvaluationContextRecord::EK_Decltype); |
| 6056 | |
| 6057 | ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); |
| 6058 | if (E.isInvalid()) |
| 6059 | return QualType(); |
| 6060 | |
| 6061 | E = getSema().ActOnDecltypeExpression(E.get()); |
| 6062 | if (E.isInvalid()) |
| 6063 | return QualType(); |
| 6064 | |
| 6065 | QualType Result = TL.getType(); |
| 6066 | if (getDerived().AlwaysRebuild() || |
| 6067 | E.get() != T->getUnderlyingExpr()) { |
| 6068 | Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); |
| 6069 | if (Result.isNull()) |
| 6070 | return QualType(); |
| 6071 | } |
| 6072 | else E.get(); |
| 6073 | |
| 6074 | DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); |
| 6075 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6076 | |
| 6077 | return Result; |
| 6078 | } |
| 6079 | |
| 6080 | template<typename Derived> |
| 6081 | QualType TreeTransform<Derived>::TransformUnaryTransformType( |
| 6082 | TypeLocBuilder &TLB, |
| 6083 | UnaryTransformTypeLoc TL) { |
| 6084 | QualType Result = TL.getType(); |
| 6085 | if (Result->isDependentType()) { |
| 6086 | const UnaryTransformType *T = TL.getTypePtr(); |
| 6087 | QualType NewBase = |
| 6088 | getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); |
| 6089 | Result = getDerived().RebuildUnaryTransformType(NewBase, |
| 6090 | T->getUTTKind(), |
| 6091 | TL.getKWLoc()); |
| 6092 | if (Result.isNull()) |
| 6093 | return QualType(); |
| 6094 | } |
| 6095 | |
| 6096 | UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); |
| 6097 | NewTL.setKWLoc(TL.getKWLoc()); |
| 6098 | NewTL.setParensRange(TL.getParensRange()); |
| 6099 | NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); |
| 6100 | return Result; |
| 6101 | } |
| 6102 | |
| 6103 | template<typename Derived> |
| 6104 | QualType TreeTransform<Derived>::TransformDeducedTemplateSpecializationType( |
| 6105 | TypeLocBuilder &TLB, DeducedTemplateSpecializationTypeLoc TL) { |
| 6106 | const DeducedTemplateSpecializationType *T = TL.getTypePtr(); |
| 6107 | |
| 6108 | CXXScopeSpec SS; |
| 6109 | TemplateName TemplateName = getDerived().TransformTemplateName( |
| 6110 | SS, T->getTemplateName(), TL.getTemplateNameLoc()); |
| 6111 | if (TemplateName.isNull()) |
| 6112 | return QualType(); |
| 6113 | |
| 6114 | QualType OldDeduced = T->getDeducedType(); |
| 6115 | QualType NewDeduced; |
| 6116 | if (!OldDeduced.isNull()) { |
| 6117 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 6118 | if (NewDeduced.isNull()) |
| 6119 | return QualType(); |
| 6120 | } |
| 6121 | |
| 6122 | QualType Result = getDerived().RebuildDeducedTemplateSpecializationType( |
| 6123 | TemplateName, NewDeduced); |
| 6124 | if (Result.isNull()) |
| 6125 | return QualType(); |
| 6126 | |
| 6127 | DeducedTemplateSpecializationTypeLoc NewTL = |
| 6128 | TLB.push<DeducedTemplateSpecializationTypeLoc>(Result); |
| 6129 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 6130 | |
| 6131 | return Result; |
| 6132 | } |
| 6133 | |
| 6134 | template<typename Derived> |
| 6135 | QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, |
| 6136 | RecordTypeLoc TL) { |
| 6137 | const RecordType *T = TL.getTypePtr(); |
| 6138 | RecordDecl *Record |
| 6139 | = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 6140 | T->getDecl())); |
| 6141 | if (!Record) |
| 6142 | return QualType(); |
| 6143 | |
| 6144 | QualType Result = TL.getType(); |
| 6145 | if (getDerived().AlwaysRebuild() || |
| 6146 | Record != T->getDecl()) { |
| 6147 | Result = getDerived().RebuildRecordType(Record); |
| 6148 | if (Result.isNull()) |
| 6149 | return QualType(); |
| 6150 | } |
| 6151 | |
| 6152 | RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); |
| 6153 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6154 | |
| 6155 | return Result; |
| 6156 | } |
| 6157 | |
| 6158 | template<typename Derived> |
| 6159 | QualType TreeTransform<Derived>::(TypeLocBuilder &TLB, |
| 6160 | EnumTypeLoc TL) { |
| 6161 | const EnumType *T = TL.getTypePtr(); |
| 6162 | EnumDecl *Enum |
| 6163 | = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), |
| 6164 | T->getDecl())); |
| 6165 | if (!Enum) |
| 6166 | return QualType(); |
| 6167 | |
| 6168 | QualType Result = TL.getType(); |
| 6169 | if (getDerived().AlwaysRebuild() || |
| 6170 | Enum != T->getDecl()) { |
| 6171 | Result = getDerived().RebuildEnumType(Enum); |
| 6172 | if (Result.isNull()) |
| 6173 | return QualType(); |
| 6174 | } |
| 6175 | |
| 6176 | EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); |
| 6177 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6178 | |
| 6179 | return Result; |
| 6180 | } |
| 6181 | |
| 6182 | template<typename Derived> |
| 6183 | QualType TreeTransform<Derived>::TransformInjectedClassNameType( |
| 6184 | TypeLocBuilder &TLB, |
| 6185 | InjectedClassNameTypeLoc TL) { |
| 6186 | Decl *D = getDerived().TransformDecl(TL.getNameLoc(), |
| 6187 | TL.getTypePtr()->getDecl()); |
| 6188 | if (!D) return QualType(); |
| 6189 | |
| 6190 | QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); |
| 6191 | TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); |
| 6192 | return T; |
| 6193 | } |
| 6194 | |
| 6195 | template<typename Derived> |
| 6196 | QualType TreeTransform<Derived>::TransformTemplateTypeParmType( |
| 6197 | TypeLocBuilder &TLB, |
| 6198 | TemplateTypeParmTypeLoc TL) { |
| 6199 | return TransformTypeSpecType(TLB, TL); |
| 6200 | } |
| 6201 | |
| 6202 | template<typename Derived> |
| 6203 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( |
| 6204 | TypeLocBuilder &TLB, |
| 6205 | SubstTemplateTypeParmTypeLoc TL) { |
| 6206 | const SubstTemplateTypeParmType *T = TL.getTypePtr(); |
| 6207 | |
| 6208 | // Substitute into the replacement type, which itself might involve something |
| 6209 | // that needs to be transformed. This only tends to occur with default |
| 6210 | // template arguments of template template parameters. |
| 6211 | TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); |
| 6212 | QualType Replacement = getDerived().TransformType(T->getReplacementType()); |
| 6213 | if (Replacement.isNull()) |
| 6214 | return QualType(); |
| 6215 | |
| 6216 | // Always canonicalize the replacement type. |
| 6217 | Replacement = SemaRef.Context.getCanonicalType(Replacement); |
| 6218 | QualType Result |
| 6219 | = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), |
| 6220 | Replacement); |
| 6221 | |
| 6222 | // Propagate type-source information. |
| 6223 | SubstTemplateTypeParmTypeLoc NewTL |
| 6224 | = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); |
| 6225 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6226 | return Result; |
| 6227 | |
| 6228 | } |
| 6229 | |
| 6230 | template<typename Derived> |
| 6231 | QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( |
| 6232 | TypeLocBuilder &TLB, |
| 6233 | SubstTemplateTypeParmPackTypeLoc TL) { |
| 6234 | return TransformTypeSpecType(TLB, TL); |
| 6235 | } |
| 6236 | |
| 6237 | template<typename Derived> |
| 6238 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 6239 | TypeLocBuilder &TLB, |
| 6240 | TemplateSpecializationTypeLoc TL) { |
| 6241 | const TemplateSpecializationType *T = TL.getTypePtr(); |
| 6242 | |
| 6243 | // The nested-name-specifier never matters in a TemplateSpecializationType, |
| 6244 | // because we can't have a dependent nested-name-specifier anyway. |
| 6245 | CXXScopeSpec SS; |
| 6246 | TemplateName Template |
| 6247 | = getDerived().TransformTemplateName(SS, T->getTemplateName(), |
| 6248 | TL.getTemplateNameLoc()); |
| 6249 | if (Template.isNull()) |
| 6250 | return QualType(); |
| 6251 | |
| 6252 | return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); |
| 6253 | } |
| 6254 | |
| 6255 | template<typename Derived> |
| 6256 | QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, |
| 6257 | AtomicTypeLoc TL) { |
| 6258 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 6259 | if (ValueType.isNull()) |
| 6260 | return QualType(); |
| 6261 | |
| 6262 | QualType Result = TL.getType(); |
| 6263 | if (getDerived().AlwaysRebuild() || |
| 6264 | ValueType != TL.getValueLoc().getType()) { |
| 6265 | Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); |
| 6266 | if (Result.isNull()) |
| 6267 | return QualType(); |
| 6268 | } |
| 6269 | |
| 6270 | AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); |
| 6271 | NewTL.setKWLoc(TL.getKWLoc()); |
| 6272 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 6273 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 6274 | |
| 6275 | return Result; |
| 6276 | } |
| 6277 | |
| 6278 | template <typename Derived> |
| 6279 | QualType TreeTransform<Derived>::TransformPipeType(TypeLocBuilder &TLB, |
| 6280 | PipeTypeLoc TL) { |
| 6281 | QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); |
| 6282 | if (ValueType.isNull()) |
| 6283 | return QualType(); |
| 6284 | |
| 6285 | QualType Result = TL.getType(); |
| 6286 | if (getDerived().AlwaysRebuild() || ValueType != TL.getValueLoc().getType()) { |
| 6287 | const PipeType *PT = Result->castAs<PipeType>(); |
| 6288 | bool isReadPipe = PT->isReadOnly(); |
| 6289 | Result = getDerived().RebuildPipeType(ValueType, TL.getKWLoc(), isReadPipe); |
| 6290 | if (Result.isNull()) |
| 6291 | return QualType(); |
| 6292 | } |
| 6293 | |
| 6294 | PipeTypeLoc NewTL = TLB.push<PipeTypeLoc>(Result); |
| 6295 | NewTL.setKWLoc(TL.getKWLoc()); |
| 6296 | |
| 6297 | return Result; |
| 6298 | } |
| 6299 | |
| 6300 | template <typename Derived> |
| 6301 | QualType TreeTransform<Derived>::TransformExtIntType(TypeLocBuilder &TLB, |
| 6302 | ExtIntTypeLoc TL) { |
| 6303 | const ExtIntType *EIT = TL.getTypePtr(); |
| 6304 | QualType Result = TL.getType(); |
| 6305 | |
| 6306 | if (getDerived().AlwaysRebuild()) { |
| 6307 | Result = getDerived().RebuildExtIntType(EIT->isUnsigned(), |
| 6308 | EIT->getNumBits(), TL.getNameLoc()); |
| 6309 | if (Result.isNull()) |
| 6310 | return QualType(); |
| 6311 | } |
| 6312 | |
| 6313 | ExtIntTypeLoc NewTL = TLB.push<ExtIntTypeLoc>(Result); |
| 6314 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6315 | return Result; |
| 6316 | } |
| 6317 | |
| 6318 | template <typename Derived> |
| 6319 | QualType TreeTransform<Derived>::TransformDependentExtIntType( |
| 6320 | TypeLocBuilder &TLB, DependentExtIntTypeLoc TL) { |
| 6321 | const DependentExtIntType *EIT = TL.getTypePtr(); |
| 6322 | |
| 6323 | EnterExpressionEvaluationContext Unevaluated( |
| 6324 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 6325 | ExprResult BitsExpr = getDerived().TransformExpr(EIT->getNumBitsExpr()); |
| 6326 | BitsExpr = SemaRef.ActOnConstantExpression(BitsExpr); |
| 6327 | |
| 6328 | if (BitsExpr.isInvalid()) |
| 6329 | return QualType(); |
| 6330 | |
| 6331 | QualType Result = TL.getType(); |
| 6332 | |
| 6333 | if (getDerived().AlwaysRebuild() || BitsExpr.get() != EIT->getNumBitsExpr()) { |
| 6334 | Result = getDerived().RebuildDependentExtIntType( |
| 6335 | EIT->isUnsigned(), BitsExpr.get(), TL.getNameLoc()); |
| 6336 | |
| 6337 | if (Result.isNull()) |
| 6338 | return QualType(); |
| 6339 | } |
| 6340 | |
| 6341 | if (isa<DependentExtIntType>(Result)) { |
| 6342 | DependentExtIntTypeLoc NewTL = TLB.push<DependentExtIntTypeLoc>(Result); |
| 6343 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6344 | } else { |
| 6345 | ExtIntTypeLoc NewTL = TLB.push<ExtIntTypeLoc>(Result); |
| 6346 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6347 | } |
| 6348 | return Result; |
| 6349 | } |
| 6350 | |
| 6351 | /// Simple iterator that traverses the template arguments in a |
| 6352 | /// container that provides a \c getArgLoc() member function. |
| 6353 | /// |
| 6354 | /// This iterator is intended to be used with the iterator form of |
| 6355 | /// \c TreeTransform<Derived>::TransformTemplateArguments(). |
| 6356 | template<typename ArgLocContainer> |
| 6357 | class TemplateArgumentLocContainerIterator { |
| 6358 | ArgLocContainer *Container; |
| 6359 | unsigned Index; |
| 6360 | |
| 6361 | public: |
| 6362 | typedef TemplateArgumentLoc value_type; |
| 6363 | typedef TemplateArgumentLoc reference; |
| 6364 | typedef int difference_type; |
| 6365 | typedef std::input_iterator_tag iterator_category; |
| 6366 | |
| 6367 | class pointer { |
| 6368 | TemplateArgumentLoc Arg; |
| 6369 | |
| 6370 | public: |
| 6371 | explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } |
| 6372 | |
| 6373 | const TemplateArgumentLoc *operator->() const { |
| 6374 | return &Arg; |
| 6375 | } |
| 6376 | }; |
| 6377 | |
| 6378 | |
| 6379 | TemplateArgumentLocContainerIterator() {} |
| 6380 | |
| 6381 | TemplateArgumentLocContainerIterator(ArgLocContainer &Container, |
| 6382 | unsigned Index) |
| 6383 | : Container(&Container), Index(Index) { } |
| 6384 | |
| 6385 | TemplateArgumentLocContainerIterator &operator++() { |
| 6386 | ++Index; |
| 6387 | return *this; |
| 6388 | } |
| 6389 | |
| 6390 | TemplateArgumentLocContainerIterator operator++(int) { |
| 6391 | TemplateArgumentLocContainerIterator Old(*this); |
| 6392 | ++(*this); |
| 6393 | return Old; |
| 6394 | } |
| 6395 | |
| 6396 | TemplateArgumentLoc operator*() const { |
| 6397 | return Container->getArgLoc(Index); |
| 6398 | } |
| 6399 | |
| 6400 | pointer operator->() const { |
| 6401 | return pointer(Container->getArgLoc(Index)); |
| 6402 | } |
| 6403 | |
| 6404 | friend bool operator==(const TemplateArgumentLocContainerIterator &X, |
| 6405 | const TemplateArgumentLocContainerIterator &Y) { |
| 6406 | return X.Container == Y.Container && X.Index == Y.Index; |
| 6407 | } |
| 6408 | |
| 6409 | friend bool operator!=(const TemplateArgumentLocContainerIterator &X, |
| 6410 | const TemplateArgumentLocContainerIterator &Y) { |
| 6411 | return !(X == Y); |
| 6412 | } |
| 6413 | }; |
| 6414 | |
| 6415 | template<typename Derived> |
| 6416 | QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, |
| 6417 | AutoTypeLoc TL) { |
| 6418 | const AutoType *T = TL.getTypePtr(); |
| 6419 | QualType OldDeduced = T->getDeducedType(); |
| 6420 | QualType NewDeduced; |
| 6421 | if (!OldDeduced.isNull()) { |
| 6422 | NewDeduced = getDerived().TransformType(OldDeduced); |
| 6423 | if (NewDeduced.isNull()) |
| 6424 | return QualType(); |
| 6425 | } |
| 6426 | |
| 6427 | ConceptDecl *NewCD = nullptr; |
| 6428 | TemplateArgumentListInfo NewTemplateArgs; |
| 6429 | NestedNameSpecifierLoc NewNestedNameSpec; |
| 6430 | if (TL.getTypePtr()->isConstrained()) { |
| 6431 | NewCD = cast_or_null<ConceptDecl>( |
| 6432 | getDerived().TransformDecl( |
| 6433 | TL.getConceptNameLoc(), |
| 6434 | TL.getTypePtr()->getTypeConstraintConcept())); |
| 6435 | |
| 6436 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 6437 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 6438 | typedef TemplateArgumentLocContainerIterator<AutoTypeLoc> ArgIterator; |
| 6439 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 6440 | ArgIterator(TL, |
| 6441 | TL.getNumArgs()), |
| 6442 | NewTemplateArgs)) |
| 6443 | return QualType(); |
| 6444 | |
| 6445 | if (TL.getNestedNameSpecifierLoc()) { |
| 6446 | NewNestedNameSpec |
| 6447 | = getDerived().TransformNestedNameSpecifierLoc( |
| 6448 | TL.getNestedNameSpecifierLoc()); |
| 6449 | if (!NewNestedNameSpec) |
| 6450 | return QualType(); |
| 6451 | } |
| 6452 | } |
| 6453 | |
| 6454 | QualType Result = TL.getType(); |
| 6455 | if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced || |
| 6456 | T->isDependentType()) { |
| 6457 | llvm::SmallVector<TemplateArgument, 4> NewArgList; |
| 6458 | NewArgList.reserve(NewArgList.size()); |
| 6459 | for (const auto &ArgLoc : NewTemplateArgs.arguments()) |
| 6460 | NewArgList.push_back(ArgLoc.getArgument()); |
| 6461 | Result = getDerived().RebuildAutoType(NewDeduced, T->getKeyword(), NewCD, |
| 6462 | NewArgList); |
| 6463 | if (Result.isNull()) |
| 6464 | return QualType(); |
| 6465 | } |
| 6466 | |
| 6467 | AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); |
| 6468 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6469 | NewTL.setNestedNameSpecifierLoc(NewNestedNameSpec); |
| 6470 | NewTL.setTemplateKWLoc(TL.getTemplateKWLoc()); |
| 6471 | NewTL.setConceptNameLoc(TL.getConceptNameLoc()); |
| 6472 | NewTL.setFoundDecl(TL.getFoundDecl()); |
| 6473 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6474 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6475 | for (unsigned I = 0; I < TL.getNumArgs(); ++I) |
| 6476 | NewTL.setArgLocInfo(I, NewTemplateArgs.arguments()[I].getLocInfo()); |
| 6477 | |
| 6478 | return Result; |
| 6479 | } |
| 6480 | |
| 6481 | template <typename Derived> |
| 6482 | QualType TreeTransform<Derived>::TransformTemplateSpecializationType( |
| 6483 | TypeLocBuilder &TLB, |
| 6484 | TemplateSpecializationTypeLoc TL, |
| 6485 | TemplateName Template) { |
| 6486 | TemplateArgumentListInfo NewTemplateArgs; |
| 6487 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 6488 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 6489 | typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> |
| 6490 | ArgIterator; |
| 6491 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 6492 | ArgIterator(TL, TL.getNumArgs()), |
| 6493 | NewTemplateArgs)) |
| 6494 | return QualType(); |
| 6495 | |
| 6496 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 6497 | |
| 6498 | QualType Result = |
| 6499 | getDerived().RebuildTemplateSpecializationType(Template, |
| 6500 | TL.getTemplateNameLoc(), |
| 6501 | NewTemplateArgs); |
| 6502 | |
| 6503 | if (!Result.isNull()) { |
| 6504 | // Specializations of template template parameters are represented as |
| 6505 | // TemplateSpecializationTypes, and substitution of type alias templates |
| 6506 | // within a dependent context can transform them into |
| 6507 | // DependentTemplateSpecializationTypes. |
| 6508 | if (isa<DependentTemplateSpecializationType>(Result)) { |
| 6509 | DependentTemplateSpecializationTypeLoc NewTL |
| 6510 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| 6511 | NewTL.setElaboratedKeywordLoc(SourceLocation()); |
| 6512 | NewTL.setQualifierLoc(NestedNameSpecifierLoc()); |
| 6513 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| 6514 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 6515 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6516 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6517 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6518 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 6519 | return Result; |
| 6520 | } |
| 6521 | |
| 6522 | TemplateSpecializationTypeLoc NewTL |
| 6523 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 6524 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| 6525 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 6526 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6527 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6528 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6529 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 6530 | } |
| 6531 | |
| 6532 | return Result; |
| 6533 | } |
| 6534 | |
| 6535 | template <typename Derived> |
| 6536 | QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( |
| 6537 | TypeLocBuilder &TLB, |
| 6538 | DependentTemplateSpecializationTypeLoc TL, |
| 6539 | TemplateName Template, |
| 6540 | CXXScopeSpec &SS) { |
| 6541 | TemplateArgumentListInfo NewTemplateArgs; |
| 6542 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 6543 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 6544 | typedef TemplateArgumentLocContainerIterator< |
| 6545 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 6546 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 6547 | ArgIterator(TL, TL.getNumArgs()), |
| 6548 | NewTemplateArgs)) |
| 6549 | return QualType(); |
| 6550 | |
| 6551 | // FIXME: maybe don't rebuild if all the template arguments are the same. |
| 6552 | |
| 6553 | if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { |
| 6554 | QualType Result |
| 6555 | = getSema().Context.getDependentTemplateSpecializationType( |
| 6556 | TL.getTypePtr()->getKeyword(), |
| 6557 | DTN->getQualifier(), |
| 6558 | DTN->getIdentifier(), |
| 6559 | NewTemplateArgs); |
| 6560 | |
| 6561 | DependentTemplateSpecializationTypeLoc NewTL |
| 6562 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| 6563 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 6564 | NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); |
| 6565 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| 6566 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 6567 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6568 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6569 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6570 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 6571 | return Result; |
| 6572 | } |
| 6573 | |
| 6574 | QualType Result |
| 6575 | = getDerived().RebuildTemplateSpecializationType(Template, |
| 6576 | TL.getTemplateNameLoc(), |
| 6577 | NewTemplateArgs); |
| 6578 | |
| 6579 | if (!Result.isNull()) { |
| 6580 | /// FIXME: Wrap this in an elaborated-type-specifier? |
| 6581 | TemplateSpecializationTypeLoc NewTL |
| 6582 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 6583 | NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| 6584 | NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 6585 | NewTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6586 | NewTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6587 | for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) |
| 6588 | NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); |
| 6589 | } |
| 6590 | |
| 6591 | return Result; |
| 6592 | } |
| 6593 | |
| 6594 | template<typename Derived> |
| 6595 | QualType |
| 6596 | TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, |
| 6597 | ElaboratedTypeLoc TL) { |
| 6598 | const ElaboratedType *T = TL.getTypePtr(); |
| 6599 | |
| 6600 | NestedNameSpecifierLoc QualifierLoc; |
| 6601 | // NOTE: the qualifier in an ElaboratedType is optional. |
| 6602 | if (TL.getQualifierLoc()) { |
| 6603 | QualifierLoc |
| 6604 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6605 | if (!QualifierLoc) |
| 6606 | return QualType(); |
| 6607 | } |
| 6608 | |
| 6609 | QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); |
| 6610 | if (NamedT.isNull()) |
| 6611 | return QualType(); |
| 6612 | |
| 6613 | // C++0x [dcl.type.elab]p2: |
| 6614 | // If the identifier resolves to a typedef-name or the simple-template-id |
| 6615 | // resolves to an alias template specialization, the |
| 6616 | // elaborated-type-specifier is ill-formed. |
| 6617 | if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { |
| 6618 | if (const TemplateSpecializationType *TST = |
| 6619 | NamedT->getAs<TemplateSpecializationType>()) { |
| 6620 | TemplateName Template = TST->getTemplateName(); |
| 6621 | if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>( |
| 6622 | Template.getAsTemplateDecl())) { |
| 6623 | SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), |
| 6624 | diag::err_tag_reference_non_tag) |
| 6625 | << TAT << Sema::NTK_TypeAliasTemplate |
| 6626 | << ElaboratedType::getTagTypeKindForKeyword(T->getKeyword()); |
| 6627 | SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); |
| 6628 | } |
| 6629 | } |
| 6630 | } |
| 6631 | |
| 6632 | QualType Result = TL.getType(); |
| 6633 | if (getDerived().AlwaysRebuild() || |
| 6634 | QualifierLoc != TL.getQualifierLoc() || |
| 6635 | NamedT != T->getNamedType()) { |
| 6636 | Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), |
| 6637 | T->getKeyword(), |
| 6638 | QualifierLoc, NamedT); |
| 6639 | if (Result.isNull()) |
| 6640 | return QualType(); |
| 6641 | } |
| 6642 | |
| 6643 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 6644 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 6645 | NewTL.setQualifierLoc(QualifierLoc); |
| 6646 | return Result; |
| 6647 | } |
| 6648 | |
| 6649 | template<typename Derived> |
| 6650 | QualType TreeTransform<Derived>::TransformAttributedType( |
| 6651 | TypeLocBuilder &TLB, |
| 6652 | AttributedTypeLoc TL) { |
| 6653 | const AttributedType *oldType = TL.getTypePtr(); |
| 6654 | QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); |
| 6655 | if (modifiedType.isNull()) |
| 6656 | return QualType(); |
| 6657 | |
| 6658 | // oldAttr can be null if we started with a QualType rather than a TypeLoc. |
| 6659 | const Attr *oldAttr = TL.getAttr(); |
| 6660 | const Attr *newAttr = oldAttr ? getDerived().TransformAttr(oldAttr) : nullptr; |
| 6661 | if (oldAttr && !newAttr) |
| 6662 | return QualType(); |
| 6663 | |
| 6664 | QualType result = TL.getType(); |
| 6665 | |
| 6666 | // FIXME: dependent operand expressions? |
| 6667 | if (getDerived().AlwaysRebuild() || |
| 6668 | modifiedType != oldType->getModifiedType()) { |
| 6669 | // TODO: this is really lame; we should really be rebuilding the |
| 6670 | // equivalent type from first principles. |
| 6671 | QualType equivalentType |
| 6672 | = getDerived().TransformType(oldType->getEquivalentType()); |
| 6673 | if (equivalentType.isNull()) |
| 6674 | return QualType(); |
| 6675 | |
| 6676 | // Check whether we can add nullability; it is only represented as |
| 6677 | // type sugar, and therefore cannot be diagnosed in any other way. |
| 6678 | if (auto nullability = oldType->getImmediateNullability()) { |
| 6679 | if (!modifiedType->canHaveNullability()) { |
| 6680 | SemaRef.Diag(TL.getAttr()->getLocation(), |
| 6681 | diag::err_nullability_nonpointer) |
| 6682 | << DiagNullabilityKind(*nullability, false) << modifiedType; |
| 6683 | return QualType(); |
| 6684 | } |
| 6685 | } |
| 6686 | |
| 6687 | result = SemaRef.Context.getAttributedType(TL.getAttrKind(), |
| 6688 | modifiedType, |
| 6689 | equivalentType); |
| 6690 | } |
| 6691 | |
| 6692 | AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); |
| 6693 | newTL.setAttr(newAttr); |
| 6694 | return result; |
| 6695 | } |
| 6696 | |
| 6697 | template<typename Derived> |
| 6698 | QualType |
| 6699 | TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, |
| 6700 | ParenTypeLoc TL) { |
| 6701 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 6702 | if (Inner.isNull()) |
| 6703 | return QualType(); |
| 6704 | |
| 6705 | QualType Result = TL.getType(); |
| 6706 | if (getDerived().AlwaysRebuild() || |
| 6707 | Inner != TL.getInnerLoc().getType()) { |
| 6708 | Result = getDerived().RebuildParenType(Inner); |
| 6709 | if (Result.isNull()) |
| 6710 | return QualType(); |
| 6711 | } |
| 6712 | |
| 6713 | ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); |
| 6714 | NewTL.setLParenLoc(TL.getLParenLoc()); |
| 6715 | NewTL.setRParenLoc(TL.getRParenLoc()); |
| 6716 | return Result; |
| 6717 | } |
| 6718 | |
| 6719 | template <typename Derived> |
| 6720 | QualType |
| 6721 | TreeTransform<Derived>::TransformMacroQualifiedType(TypeLocBuilder &TLB, |
| 6722 | MacroQualifiedTypeLoc TL) { |
| 6723 | QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); |
| 6724 | if (Inner.isNull()) |
| 6725 | return QualType(); |
| 6726 | |
| 6727 | QualType Result = TL.getType(); |
| 6728 | if (getDerived().AlwaysRebuild() || Inner != TL.getInnerLoc().getType()) { |
| 6729 | Result = |
| 6730 | getDerived().RebuildMacroQualifiedType(Inner, TL.getMacroIdentifier()); |
| 6731 | if (Result.isNull()) |
| 6732 | return QualType(); |
| 6733 | } |
| 6734 | |
| 6735 | MacroQualifiedTypeLoc NewTL = TLB.push<MacroQualifiedTypeLoc>(Result); |
| 6736 | NewTL.setExpansionLoc(TL.getExpansionLoc()); |
| 6737 | return Result; |
| 6738 | } |
| 6739 | |
| 6740 | template<typename Derived> |
| 6741 | QualType TreeTransform<Derived>::TransformDependentNameType( |
| 6742 | TypeLocBuilder &TLB, DependentNameTypeLoc TL) { |
| 6743 | return TransformDependentNameType(TLB, TL, false); |
| 6744 | } |
| 6745 | |
| 6746 | template<typename Derived> |
| 6747 | QualType TreeTransform<Derived>::TransformDependentNameType( |
| 6748 | TypeLocBuilder &TLB, DependentNameTypeLoc TL, bool DeducedTSTContext) { |
| 6749 | const DependentNameType *T = TL.getTypePtr(); |
| 6750 | |
| 6751 | NestedNameSpecifierLoc QualifierLoc |
| 6752 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6753 | if (!QualifierLoc) |
| 6754 | return QualType(); |
| 6755 | |
| 6756 | QualType Result |
| 6757 | = getDerived().RebuildDependentNameType(T->getKeyword(), |
| 6758 | TL.getElaboratedKeywordLoc(), |
| 6759 | QualifierLoc, |
| 6760 | T->getIdentifier(), |
| 6761 | TL.getNameLoc(), |
| 6762 | DeducedTSTContext); |
| 6763 | if (Result.isNull()) |
| 6764 | return QualType(); |
| 6765 | |
| 6766 | if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { |
| 6767 | QualType NamedT = ElabT->getNamedType(); |
| 6768 | TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); |
| 6769 | |
| 6770 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 6771 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 6772 | NewTL.setQualifierLoc(QualifierLoc); |
| 6773 | } else { |
| 6774 | DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); |
| 6775 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 6776 | NewTL.setQualifierLoc(QualifierLoc); |
| 6777 | NewTL.setNameLoc(TL.getNameLoc()); |
| 6778 | } |
| 6779 | return Result; |
| 6780 | } |
| 6781 | |
| 6782 | template<typename Derived> |
| 6783 | QualType TreeTransform<Derived>:: |
| 6784 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 6785 | DependentTemplateSpecializationTypeLoc TL) { |
| 6786 | NestedNameSpecifierLoc QualifierLoc; |
| 6787 | if (TL.getQualifierLoc()) { |
| 6788 | QualifierLoc |
| 6789 | = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); |
| 6790 | if (!QualifierLoc) |
| 6791 | return QualType(); |
| 6792 | } |
| 6793 | |
| 6794 | return getDerived() |
| 6795 | .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); |
| 6796 | } |
| 6797 | |
| 6798 | template<typename Derived> |
| 6799 | QualType TreeTransform<Derived>:: |
| 6800 | TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, |
| 6801 | DependentTemplateSpecializationTypeLoc TL, |
| 6802 | NestedNameSpecifierLoc QualifierLoc) { |
| 6803 | const DependentTemplateSpecializationType *T = TL.getTypePtr(); |
| 6804 | |
| 6805 | TemplateArgumentListInfo NewTemplateArgs; |
| 6806 | NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); |
| 6807 | NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); |
| 6808 | |
| 6809 | typedef TemplateArgumentLocContainerIterator< |
| 6810 | DependentTemplateSpecializationTypeLoc> ArgIterator; |
| 6811 | if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), |
| 6812 | ArgIterator(TL, TL.getNumArgs()), |
| 6813 | NewTemplateArgs)) |
| 6814 | return QualType(); |
| 6815 | |
| 6816 | QualType Result = getDerived().RebuildDependentTemplateSpecializationType( |
| 6817 | T->getKeyword(), QualifierLoc, TL.getTemplateKeywordLoc(), |
| 6818 | T->getIdentifier(), TL.getTemplateNameLoc(), NewTemplateArgs, |
| 6819 | /*AllowInjectedClassName*/ false); |
| 6820 | if (Result.isNull()) |
| 6821 | return QualType(); |
| 6822 | |
| 6823 | if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { |
| 6824 | QualType NamedT = ElabT->getNamedType(); |
| 6825 | |
| 6826 | // Copy information relevant to the template specialization. |
| 6827 | TemplateSpecializationTypeLoc NamedTL |
| 6828 | = TLB.push<TemplateSpecializationTypeLoc>(NamedT); |
| 6829 | NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| 6830 | NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 6831 | NamedTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6832 | NamedTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6833 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| 6834 | NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| 6835 | |
| 6836 | // Copy information relevant to the elaborated type. |
| 6837 | ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); |
| 6838 | NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 6839 | NewTL.setQualifierLoc(QualifierLoc); |
| 6840 | } else if (isa<DependentTemplateSpecializationType>(Result)) { |
| 6841 | DependentTemplateSpecializationTypeLoc SpecTL |
| 6842 | = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); |
| 6843 | SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); |
| 6844 | SpecTL.setQualifierLoc(QualifierLoc); |
| 6845 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| 6846 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 6847 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6848 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6849 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| 6850 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| 6851 | } else { |
| 6852 | TemplateSpecializationTypeLoc SpecTL |
| 6853 | = TLB.push<TemplateSpecializationTypeLoc>(Result); |
| 6854 | SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); |
| 6855 | SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); |
| 6856 | SpecTL.setLAngleLoc(TL.getLAngleLoc()); |
| 6857 | SpecTL.setRAngleLoc(TL.getRAngleLoc()); |
| 6858 | for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) |
| 6859 | SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); |
| 6860 | } |
| 6861 | return Result; |
| 6862 | } |
| 6863 | |
| 6864 | template<typename Derived> |
| 6865 | QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, |
| 6866 | PackExpansionTypeLoc TL) { |
| 6867 | QualType Pattern |
| 6868 | = getDerived().TransformType(TLB, TL.getPatternLoc()); |
| 6869 | if (Pattern.isNull()) |
| 6870 | return QualType(); |
| 6871 | |
| 6872 | QualType Result = TL.getType(); |
| 6873 | if (getDerived().AlwaysRebuild() || |
| 6874 | Pattern != TL.getPatternLoc().getType()) { |
| 6875 | Result = getDerived().RebuildPackExpansionType(Pattern, |
| 6876 | TL.getPatternLoc().getSourceRange(), |
| 6877 | TL.getEllipsisLoc(), |
| 6878 | TL.getTypePtr()->getNumExpansions()); |
| 6879 | if (Result.isNull()) |
| 6880 | return QualType(); |
| 6881 | } |
| 6882 | |
| 6883 | PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); |
| 6884 | NewT.setEllipsisLoc(TL.getEllipsisLoc()); |
| 6885 | return Result; |
| 6886 | } |
| 6887 | |
| 6888 | template<typename Derived> |
| 6889 | QualType |
| 6890 | TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, |
| 6891 | ObjCInterfaceTypeLoc TL) { |
| 6892 | // ObjCInterfaceType is never dependent. |
| 6893 | TLB.pushFullCopy(TL); |
| 6894 | return TL.getType(); |
| 6895 | } |
| 6896 | |
| 6897 | template<typename Derived> |
| 6898 | QualType |
| 6899 | TreeTransform<Derived>::TransformObjCTypeParamType(TypeLocBuilder &TLB, |
| 6900 | ObjCTypeParamTypeLoc TL) { |
| 6901 | const ObjCTypeParamType *T = TL.getTypePtr(); |
| 6902 | ObjCTypeParamDecl *OTP = cast_or_null<ObjCTypeParamDecl>( |
| 6903 | getDerived().TransformDecl(T->getDecl()->getLocation(), T->getDecl())); |
| 6904 | if (!OTP) |
| 6905 | return QualType(); |
| 6906 | |
| 6907 | QualType Result = TL.getType(); |
| 6908 | if (getDerived().AlwaysRebuild() || |
| 6909 | OTP != T->getDecl()) { |
| 6910 | Result = getDerived().RebuildObjCTypeParamType(OTP, |
| 6911 | TL.getProtocolLAngleLoc(), |
| 6912 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), |
| 6913 | TL.getNumProtocols()), |
| 6914 | TL.getProtocolLocs(), |
| 6915 | TL.getProtocolRAngleLoc()); |
| 6916 | if (Result.isNull()) |
| 6917 | return QualType(); |
| 6918 | } |
| 6919 | |
| 6920 | ObjCTypeParamTypeLoc NewTL = TLB.push<ObjCTypeParamTypeLoc>(Result); |
| 6921 | if (TL.getNumProtocols()) { |
| 6922 | NewTL.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 6923 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 6924 | NewTL.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 6925 | NewTL.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 6926 | } |
| 6927 | return Result; |
| 6928 | } |
| 6929 | |
| 6930 | template<typename Derived> |
| 6931 | QualType |
| 6932 | TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, |
| 6933 | ObjCObjectTypeLoc TL) { |
| 6934 | // Transform base type. |
| 6935 | QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc()); |
| 6936 | if (BaseType.isNull()) |
| 6937 | return QualType(); |
| 6938 | |
| 6939 | bool AnyChanged = BaseType != TL.getBaseLoc().getType(); |
| 6940 | |
| 6941 | // Transform type arguments. |
| 6942 | SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos; |
| 6943 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) { |
| 6944 | TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i); |
| 6945 | TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc(); |
| 6946 | QualType TypeArg = TypeArgInfo->getType(); |
| 6947 | if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) { |
| 6948 | AnyChanged = true; |
| 6949 | |
| 6950 | // We have a pack expansion. Instantiate it. |
| 6951 | const auto *PackExpansion = PackExpansionLoc.getType() |
| 6952 | ->castAs<PackExpansionType>(); |
| 6953 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 6954 | SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(), |
| 6955 | Unexpanded); |
| 6956 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?" ); |
| 6957 | |
| 6958 | // Determine whether the set of unexpanded parameter packs can |
| 6959 | // and should be expanded. |
| 6960 | TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc(); |
| 6961 | bool Expand = false; |
| 6962 | bool RetainExpansion = false; |
| 6963 | Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions(); |
| 6964 | if (getDerived().TryExpandParameterPacks( |
| 6965 | PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(), |
| 6966 | Unexpanded, Expand, RetainExpansion, NumExpansions)) |
| 6967 | return QualType(); |
| 6968 | |
| 6969 | if (!Expand) { |
| 6970 | // We can't expand this pack expansion into separate arguments yet; |
| 6971 | // just substitute into the pattern and create a new pack expansion |
| 6972 | // type. |
| 6973 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 6974 | |
| 6975 | TypeLocBuilder TypeArgBuilder; |
| 6976 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 6977 | QualType NewPatternType = getDerived().TransformType(TypeArgBuilder, |
| 6978 | PatternLoc); |
| 6979 | if (NewPatternType.isNull()) |
| 6980 | return QualType(); |
| 6981 | |
| 6982 | QualType NewExpansionType = SemaRef.Context.getPackExpansionType( |
| 6983 | NewPatternType, NumExpansions); |
| 6984 | auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType); |
| 6985 | NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc()); |
| 6986 | NewTypeArgInfos.push_back( |
| 6987 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType)); |
| 6988 | continue; |
| 6989 | } |
| 6990 | |
| 6991 | // Substitute into the pack expansion pattern for each slice of the |
| 6992 | // pack. |
| 6993 | for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) { |
| 6994 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx); |
| 6995 | |
| 6996 | TypeLocBuilder TypeArgBuilder; |
| 6997 | TypeArgBuilder.reserve(PatternLoc.getFullDataSize()); |
| 6998 | |
| 6999 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, |
| 7000 | PatternLoc); |
| 7001 | if (NewTypeArg.isNull()) |
| 7002 | return QualType(); |
| 7003 | |
| 7004 | NewTypeArgInfos.push_back( |
| 7005 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 7006 | } |
| 7007 | |
| 7008 | continue; |
| 7009 | } |
| 7010 | |
| 7011 | TypeLocBuilder TypeArgBuilder; |
| 7012 | TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize()); |
| 7013 | QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc); |
| 7014 | if (NewTypeArg.isNull()) |
| 7015 | return QualType(); |
| 7016 | |
| 7017 | // If nothing changed, just keep the old TypeSourceInfo. |
| 7018 | if (NewTypeArg == TypeArg) { |
| 7019 | NewTypeArgInfos.push_back(TypeArgInfo); |
| 7020 | continue; |
| 7021 | } |
| 7022 | |
| 7023 | NewTypeArgInfos.push_back( |
| 7024 | TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg)); |
| 7025 | AnyChanged = true; |
| 7026 | } |
| 7027 | |
| 7028 | QualType Result = TL.getType(); |
| 7029 | if (getDerived().AlwaysRebuild() || AnyChanged) { |
| 7030 | // Rebuild the type. |
| 7031 | Result = getDerived().RebuildObjCObjectType( |
| 7032 | BaseType, TL.getBeginLoc(), TL.getTypeArgsLAngleLoc(), NewTypeArgInfos, |
| 7033 | TL.getTypeArgsRAngleLoc(), TL.getProtocolLAngleLoc(), |
| 7034 | llvm::makeArrayRef(TL.getTypePtr()->qual_begin(), TL.getNumProtocols()), |
| 7035 | TL.getProtocolLocs(), TL.getProtocolRAngleLoc()); |
| 7036 | |
| 7037 | if (Result.isNull()) |
| 7038 | return QualType(); |
| 7039 | } |
| 7040 | |
| 7041 | ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result); |
| 7042 | NewT.setHasBaseTypeAsWritten(true); |
| 7043 | NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc()); |
| 7044 | for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) |
| 7045 | NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]); |
| 7046 | NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc()); |
| 7047 | NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc()); |
| 7048 | for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i) |
| 7049 | NewT.setProtocolLoc(i, TL.getProtocolLoc(i)); |
| 7050 | NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc()); |
| 7051 | return Result; |
| 7052 | } |
| 7053 | |
| 7054 | template<typename Derived> |
| 7055 | QualType |
| 7056 | TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, |
| 7057 | ObjCObjectPointerTypeLoc TL) { |
| 7058 | QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); |
| 7059 | if (PointeeType.isNull()) |
| 7060 | return QualType(); |
| 7061 | |
| 7062 | QualType Result = TL.getType(); |
| 7063 | if (getDerived().AlwaysRebuild() || |
| 7064 | PointeeType != TL.getPointeeLoc().getType()) { |
| 7065 | Result = getDerived().RebuildObjCObjectPointerType(PointeeType, |
| 7066 | TL.getStarLoc()); |
| 7067 | if (Result.isNull()) |
| 7068 | return QualType(); |
| 7069 | } |
| 7070 | |
| 7071 | ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); |
| 7072 | NewT.setStarLoc(TL.getStarLoc()); |
| 7073 | return Result; |
| 7074 | } |
| 7075 | |
| 7076 | //===----------------------------------------------------------------------===// |
| 7077 | // Statement transformation |
| 7078 | //===----------------------------------------------------------------------===// |
| 7079 | template<typename Derived> |
| 7080 | StmtResult |
| 7081 | TreeTransform<Derived>::TransformNullStmt(NullStmt *S) { |
| 7082 | return S; |
| 7083 | } |
| 7084 | |
| 7085 | template<typename Derived> |
| 7086 | StmtResult |
| 7087 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { |
| 7088 | return getDerived().TransformCompoundStmt(S, false); |
| 7089 | } |
| 7090 | |
| 7091 | template<typename Derived> |
| 7092 | StmtResult |
| 7093 | TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, |
| 7094 | bool IsStmtExpr) { |
| 7095 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 7096 | |
| 7097 | const Stmt *ExprResult = S->getStmtExprResult(); |
| 7098 | bool SubStmtInvalid = false; |
| 7099 | bool SubStmtChanged = false; |
| 7100 | SmallVector<Stmt*, 8> Statements; |
| 7101 | for (auto *B : S->body()) { |
| 7102 | StmtResult Result = getDerived().TransformStmt( |
| 7103 | B, IsStmtExpr && B == ExprResult ? SDK_StmtExprResult : SDK_Discarded); |
| 7104 | |
| 7105 | if (Result.isInvalid()) { |
| 7106 | // Immediately fail if this was a DeclStmt, since it's very |
| 7107 | // likely that this will cause problems for future statements. |
| 7108 | if (isa<DeclStmt>(B)) |
| 7109 | return StmtError(); |
| 7110 | |
| 7111 | // Otherwise, just keep processing substatements and fail later. |
| 7112 | SubStmtInvalid = true; |
| 7113 | continue; |
| 7114 | } |
| 7115 | |
| 7116 | SubStmtChanged = SubStmtChanged || Result.get() != B; |
| 7117 | Statements.push_back(Result.getAs<Stmt>()); |
| 7118 | } |
| 7119 | |
| 7120 | if (SubStmtInvalid) |
| 7121 | return StmtError(); |
| 7122 | |
| 7123 | if (!getDerived().AlwaysRebuild() && |
| 7124 | !SubStmtChanged) |
| 7125 | return S; |
| 7126 | |
| 7127 | return getDerived().RebuildCompoundStmt(S->getLBracLoc(), |
| 7128 | Statements, |
| 7129 | S->getRBracLoc(), |
| 7130 | IsStmtExpr); |
| 7131 | } |
| 7132 | |
| 7133 | template<typename Derived> |
| 7134 | StmtResult |
| 7135 | TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { |
| 7136 | ExprResult LHS, RHS; |
| 7137 | { |
| 7138 | EnterExpressionEvaluationContext Unevaluated( |
| 7139 | SemaRef, Sema::ExpressionEvaluationContext::ConstantEvaluated); |
| 7140 | |
| 7141 | // Transform the left-hand case value. |
| 7142 | LHS = getDerived().TransformExpr(S->getLHS()); |
| 7143 | LHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), LHS); |
| 7144 | if (LHS.isInvalid()) |
| 7145 | return StmtError(); |
| 7146 | |
| 7147 | // Transform the right-hand case value (for the GNU case-range extension). |
| 7148 | RHS = getDerived().TransformExpr(S->getRHS()); |
| 7149 | RHS = SemaRef.ActOnCaseExpr(S->getCaseLoc(), RHS); |
| 7150 | if (RHS.isInvalid()) |
| 7151 | return StmtError(); |
| 7152 | } |
| 7153 | |
| 7154 | // Build the case statement. |
| 7155 | // Case statements are always rebuilt so that they will attached to their |
| 7156 | // transformed switch statement. |
| 7157 | StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), |
| 7158 | LHS.get(), |
| 7159 | S->getEllipsisLoc(), |
| 7160 | RHS.get(), |
| 7161 | S->getColonLoc()); |
| 7162 | if (Case.isInvalid()) |
| 7163 | return StmtError(); |
| 7164 | |
| 7165 | // Transform the statement following the case |
| 7166 | StmtResult SubStmt = |
| 7167 | getDerived().TransformStmt(S->getSubStmt()); |
| 7168 | if (SubStmt.isInvalid()) |
| 7169 | return StmtError(); |
| 7170 | |
| 7171 | // Attach the body to the case statement |
| 7172 | return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); |
| 7173 | } |
| 7174 | |
| 7175 | template <typename Derived> |
| 7176 | StmtResult TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { |
| 7177 | // Transform the statement following the default case |
| 7178 | StmtResult SubStmt = |
| 7179 | getDerived().TransformStmt(S->getSubStmt()); |
| 7180 | if (SubStmt.isInvalid()) |
| 7181 | return StmtError(); |
| 7182 | |
| 7183 | // Default statements are always rebuilt |
| 7184 | return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), |
| 7185 | SubStmt.get()); |
| 7186 | } |
| 7187 | |
| 7188 | template<typename Derived> |
| 7189 | StmtResult |
| 7190 | TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S, StmtDiscardKind SDK) { |
| 7191 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); |
| 7192 | if (SubStmt.isInvalid()) |
| 7193 | return StmtError(); |
| 7194 | |
| 7195 | Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), |
| 7196 | S->getDecl()); |
| 7197 | if (!LD) |
| 7198 | return StmtError(); |
| 7199 | |
| 7200 | // If we're transforming "in-place" (we're not creating new local |
| 7201 | // declarations), assume we're replacing the old label statement |
| 7202 | // and clear out the reference to it. |
| 7203 | if (LD == S->getDecl()) |
| 7204 | S->getDecl()->setStmt(nullptr); |
| 7205 | |
| 7206 | // FIXME: Pass the real colon location in. |
| 7207 | return getDerived().RebuildLabelStmt(S->getIdentLoc(), |
| 7208 | cast<LabelDecl>(LD), SourceLocation(), |
| 7209 | SubStmt.get()); |
| 7210 | } |
| 7211 | |
| 7212 | template <typename Derived> |
| 7213 | const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) { |
| 7214 | if (!R) |
| 7215 | return R; |
| 7216 | |
| 7217 | switch (R->getKind()) { |
| 7218 | // Transform attributes with a pragma spelling by calling TransformXXXAttr. |
| 7219 | #define ATTR(X) |
| 7220 | #define PRAGMA_SPELLING_ATTR(X) \ |
| 7221 | case attr::X: \ |
| 7222 | return getDerived().Transform##X##Attr(cast<X##Attr>(R)); |
| 7223 | #include "clang/Basic/AttrList.inc" |
| 7224 | default: |
| 7225 | return R; |
| 7226 | } |
| 7227 | } |
| 7228 | |
| 7229 | template <typename Derived> |
| 7230 | StmtResult |
| 7231 | TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S, |
| 7232 | StmtDiscardKind SDK) { |
| 7233 | bool AttrsChanged = false; |
| 7234 | SmallVector<const Attr *, 1> Attrs; |
| 7235 | |
| 7236 | // Visit attributes and keep track if any are transformed. |
| 7237 | for (const auto *I : S->getAttrs()) { |
| 7238 | const Attr *R = getDerived().TransformAttr(I); |
| 7239 | AttrsChanged |= (I != R); |
| 7240 | Attrs.push_back(R); |
| 7241 | } |
| 7242 | |
| 7243 | StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt(), SDK); |
| 7244 | if (SubStmt.isInvalid()) |
| 7245 | return StmtError(); |
| 7246 | |
| 7247 | if (SubStmt.get() == S->getSubStmt() && !AttrsChanged) |
| 7248 | return S; |
| 7249 | |
| 7250 | return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs, |
| 7251 | SubStmt.get()); |
| 7252 | } |
| 7253 | |
| 7254 | template<typename Derived> |
| 7255 | StmtResult |
| 7256 | TreeTransform<Derived>::TransformIfStmt(IfStmt *S) { |
| 7257 | // Transform the initialization statement |
| 7258 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 7259 | if (Init.isInvalid()) |
| 7260 | return StmtError(); |
| 7261 | |
| 7262 | // Transform the condition |
| 7263 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 7264 | S->getIfLoc(), S->getConditionVariable(), S->getCond(), |
| 7265 | S->isConstexpr() ? Sema::ConditionKind::ConstexprIf |
| 7266 | : Sema::ConditionKind::Boolean); |
| 7267 | if (Cond.isInvalid()) |
| 7268 | return StmtError(); |
| 7269 | |
| 7270 | // If this is a constexpr if, determine which arm we should instantiate. |
| 7271 | llvm::Optional<bool> ConstexprConditionValue; |
| 7272 | if (S->isConstexpr()) |
| 7273 | ConstexprConditionValue = Cond.getKnownValue(); |
| 7274 | |
| 7275 | // Transform the "then" branch. |
| 7276 | StmtResult Then; |
| 7277 | if (!ConstexprConditionValue || *ConstexprConditionValue) { |
| 7278 | Then = getDerived().TransformStmt(S->getThen()); |
| 7279 | if (Then.isInvalid()) |
| 7280 | return StmtError(); |
| 7281 | } else { |
| 7282 | Then = new (getSema().Context) NullStmt(S->getThen()->getBeginLoc()); |
| 7283 | } |
| 7284 | |
| 7285 | // Transform the "else" branch. |
| 7286 | StmtResult Else; |
| 7287 | if (!ConstexprConditionValue || !*ConstexprConditionValue) { |
| 7288 | Else = getDerived().TransformStmt(S->getElse()); |
| 7289 | if (Else.isInvalid()) |
| 7290 | return StmtError(); |
| 7291 | } |
| 7292 | |
| 7293 | if (!getDerived().AlwaysRebuild() && |
| 7294 | Init.get() == S->getInit() && |
| 7295 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| 7296 | Then.get() == S->getThen() && |
| 7297 | Else.get() == S->getElse()) |
| 7298 | return S; |
| 7299 | |
| 7300 | return getDerived().RebuildIfStmt( |
| 7301 | S->getIfLoc(), S->isConstexpr(), S->getLParenLoc(), Cond, |
| 7302 | S->getRParenLoc(), Init.get(), Then.get(), S->getElseLoc(), Else.get()); |
| 7303 | } |
| 7304 | |
| 7305 | template<typename Derived> |
| 7306 | StmtResult |
| 7307 | TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { |
| 7308 | // Transform the initialization statement |
| 7309 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 7310 | if (Init.isInvalid()) |
| 7311 | return StmtError(); |
| 7312 | |
| 7313 | // Transform the condition. |
| 7314 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 7315 | S->getSwitchLoc(), S->getConditionVariable(), S->getCond(), |
| 7316 | Sema::ConditionKind::Switch); |
| 7317 | if (Cond.isInvalid()) |
| 7318 | return StmtError(); |
| 7319 | |
| 7320 | // Rebuild the switch statement. |
| 7321 | StmtResult Switch = |
| 7322 | getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), S->getLParenLoc(), |
| 7323 | Init.get(), Cond, S->getRParenLoc()); |
| 7324 | if (Switch.isInvalid()) |
| 7325 | return StmtError(); |
| 7326 | |
| 7327 | // Transform the body of the switch statement. |
| 7328 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 7329 | if (Body.isInvalid()) |
| 7330 | return StmtError(); |
| 7331 | |
| 7332 | // Complete the switch statement. |
| 7333 | return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), |
| 7334 | Body.get()); |
| 7335 | } |
| 7336 | |
| 7337 | template<typename Derived> |
| 7338 | StmtResult |
| 7339 | TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { |
| 7340 | // Transform the condition |
| 7341 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 7342 | S->getWhileLoc(), S->getConditionVariable(), S->getCond(), |
| 7343 | Sema::ConditionKind::Boolean); |
| 7344 | if (Cond.isInvalid()) |
| 7345 | return StmtError(); |
| 7346 | |
| 7347 | // Transform the body |
| 7348 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 7349 | if (Body.isInvalid()) |
| 7350 | return StmtError(); |
| 7351 | |
| 7352 | if (!getDerived().AlwaysRebuild() && |
| 7353 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| 7354 | Body.get() == S->getBody()) |
| 7355 | return Owned(S); |
| 7356 | |
| 7357 | return getDerived().RebuildWhileStmt(S->getWhileLoc(), S->getLParenLoc(), |
| 7358 | Cond, S->getRParenLoc(), Body.get()); |
| 7359 | } |
| 7360 | |
| 7361 | template<typename Derived> |
| 7362 | StmtResult |
| 7363 | TreeTransform<Derived>::TransformDoStmt(DoStmt *S) { |
| 7364 | // Transform the body |
| 7365 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 7366 | if (Body.isInvalid()) |
| 7367 | return StmtError(); |
| 7368 | |
| 7369 | // Transform the condition |
| 7370 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 7371 | if (Cond.isInvalid()) |
| 7372 | return StmtError(); |
| 7373 | |
| 7374 | if (!getDerived().AlwaysRebuild() && |
| 7375 | Cond.get() == S->getCond() && |
| 7376 | Body.get() == S->getBody()) |
| 7377 | return S; |
| 7378 | |
| 7379 | return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), |
| 7380 | /*FIXME:*/S->getWhileLoc(), Cond.get(), |
| 7381 | S->getRParenLoc()); |
| 7382 | } |
| 7383 | |
| 7384 | template<typename Derived> |
| 7385 | StmtResult |
| 7386 | TreeTransform<Derived>::TransformForStmt(ForStmt *S) { |
| 7387 | if (getSema().getLangOpts().OpenMP) |
| 7388 | getSema().startOpenMPLoop(); |
| 7389 | |
| 7390 | // Transform the initialization statement |
| 7391 | StmtResult Init = getDerived().TransformStmt(S->getInit()); |
| 7392 | if (Init.isInvalid()) |
| 7393 | return StmtError(); |
| 7394 | |
| 7395 | // In OpenMP loop region loop control variable must be captured and be |
| 7396 | // private. Perform analysis of first part (if any). |
| 7397 | if (getSema().getLangOpts().OpenMP && Init.isUsable()) |
| 7398 | getSema().ActOnOpenMPLoopInitialization(S->getForLoc(), Init.get()); |
| 7399 | |
| 7400 | // Transform the condition |
| 7401 | Sema::ConditionResult Cond = getDerived().TransformCondition( |
| 7402 | S->getForLoc(), S->getConditionVariable(), S->getCond(), |
| 7403 | Sema::ConditionKind::Boolean); |
| 7404 | if (Cond.isInvalid()) |
| 7405 | return StmtError(); |
| 7406 | |
| 7407 | // Transform the increment |
| 7408 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 7409 | if (Inc.isInvalid()) |
| 7410 | return StmtError(); |
| 7411 | |
| 7412 | Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get())); |
| 7413 | if (S->getInc() && !FullInc.get()) |
| 7414 | return StmtError(); |
| 7415 | |
| 7416 | // Transform the body |
| 7417 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 7418 | if (Body.isInvalid()) |
| 7419 | return StmtError(); |
| 7420 | |
| 7421 | if (!getDerived().AlwaysRebuild() && |
| 7422 | Init.get() == S->getInit() && |
| 7423 | Cond.get() == std::make_pair(S->getConditionVariable(), S->getCond()) && |
| 7424 | Inc.get() == S->getInc() && |
| 7425 | Body.get() == S->getBody()) |
| 7426 | return S; |
| 7427 | |
| 7428 | return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), |
| 7429 | Init.get(), Cond, FullInc, |
| 7430 | S->getRParenLoc(), Body.get()); |
| 7431 | } |
| 7432 | |
| 7433 | template<typename Derived> |
| 7434 | StmtResult |
| 7435 | TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { |
| 7436 | Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), |
| 7437 | S->getLabel()); |
| 7438 | if (!LD) |
| 7439 | return StmtError(); |
| 7440 | |
| 7441 | // Goto statements must always be rebuilt, to resolve the label. |
| 7442 | return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), |
| 7443 | cast<LabelDecl>(LD)); |
| 7444 | } |
| 7445 | |
| 7446 | template<typename Derived> |
| 7447 | StmtResult |
| 7448 | TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { |
| 7449 | ExprResult Target = getDerived().TransformExpr(S->getTarget()); |
| 7450 | if (Target.isInvalid()) |
| 7451 | return StmtError(); |
| 7452 | Target = SemaRef.MaybeCreateExprWithCleanups(Target.get()); |
| 7453 | |
| 7454 | if (!getDerived().AlwaysRebuild() && |
| 7455 | Target.get() == S->getTarget()) |
| 7456 | return S; |
| 7457 | |
| 7458 | return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), |
| 7459 | Target.get()); |
| 7460 | } |
| 7461 | |
| 7462 | template<typename Derived> |
| 7463 | StmtResult |
| 7464 | TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { |
| 7465 | return S; |
| 7466 | } |
| 7467 | |
| 7468 | template<typename Derived> |
| 7469 | StmtResult |
| 7470 | TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { |
| 7471 | return S; |
| 7472 | } |
| 7473 | |
| 7474 | template<typename Derived> |
| 7475 | StmtResult |
| 7476 | TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { |
| 7477 | ExprResult Result = getDerived().TransformInitializer(S->getRetValue(), |
| 7478 | /*NotCopyInit*/false); |
| 7479 | if (Result.isInvalid()) |
| 7480 | return StmtError(); |
| 7481 | |
| 7482 | // FIXME: We always rebuild the return statement because there is no way |
| 7483 | // to tell whether the return type of the function has changed. |
| 7484 | return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); |
| 7485 | } |
| 7486 | |
| 7487 | template<typename Derived> |
| 7488 | StmtResult |
| 7489 | TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { |
| 7490 | bool DeclChanged = false; |
| 7491 | SmallVector<Decl *, 4> Decls; |
| 7492 | for (auto *D : S->decls()) { |
| 7493 | Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D); |
| 7494 | if (!Transformed) |
| 7495 | return StmtError(); |
| 7496 | |
| 7497 | if (Transformed != D) |
| 7498 | DeclChanged = true; |
| 7499 | |
| 7500 | Decls.push_back(Transformed); |
| 7501 | } |
| 7502 | |
| 7503 | if (!getDerived().AlwaysRebuild() && !DeclChanged) |
| 7504 | return S; |
| 7505 | |
| 7506 | return getDerived().RebuildDeclStmt(Decls, S->getBeginLoc(), S->getEndLoc()); |
| 7507 | } |
| 7508 | |
| 7509 | template<typename Derived> |
| 7510 | StmtResult |
| 7511 | TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) { |
| 7512 | |
| 7513 | SmallVector<Expr*, 8> Constraints; |
| 7514 | SmallVector<Expr*, 8> Exprs; |
| 7515 | SmallVector<IdentifierInfo *, 4> Names; |
| 7516 | |
| 7517 | ExprResult AsmString; |
| 7518 | SmallVector<Expr*, 8> Clobbers; |
| 7519 | |
| 7520 | bool ExprsChanged = false; |
| 7521 | |
| 7522 | // Go through the outputs. |
| 7523 | for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { |
| 7524 | Names.push_back(S->getOutputIdentifier(I)); |
| 7525 | |
| 7526 | // No need to transform the constraint literal. |
| 7527 | Constraints.push_back(S->getOutputConstraintLiteral(I)); |
| 7528 | |
| 7529 | // Transform the output expr. |
| 7530 | Expr *OutputExpr = S->getOutputExpr(I); |
| 7531 | ExprResult Result = getDerived().TransformExpr(OutputExpr); |
| 7532 | if (Result.isInvalid()) |
| 7533 | return StmtError(); |
| 7534 | |
| 7535 | ExprsChanged |= Result.get() != OutputExpr; |
| 7536 | |
| 7537 | Exprs.push_back(Result.get()); |
| 7538 | } |
| 7539 | |
| 7540 | // Go through the inputs. |
| 7541 | for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { |
| 7542 | Names.push_back(S->getInputIdentifier(I)); |
| 7543 | |
| 7544 | // No need to transform the constraint literal. |
| 7545 | Constraints.push_back(S->getInputConstraintLiteral(I)); |
| 7546 | |
| 7547 | // Transform the input expr. |
| 7548 | Expr *InputExpr = S->getInputExpr(I); |
| 7549 | ExprResult Result = getDerived().TransformExpr(InputExpr); |
| 7550 | if (Result.isInvalid()) |
| 7551 | return StmtError(); |
| 7552 | |
| 7553 | ExprsChanged |= Result.get() != InputExpr; |
| 7554 | |
| 7555 | Exprs.push_back(Result.get()); |
| 7556 | } |
| 7557 | |
| 7558 | // Go through the Labels. |
| 7559 | for (unsigned I = 0, E = S->getNumLabels(); I != E; ++I) { |
| 7560 | Names.push_back(S->getLabelIdentifier(I)); |
| 7561 | |
| 7562 | ExprResult Result = getDerived().TransformExpr(S->getLabelExpr(I)); |
| 7563 | if (Result.isInvalid()) |
| 7564 | return StmtError(); |
| 7565 | ExprsChanged |= Result.get() != S->getLabelExpr(I); |
| 7566 | Exprs.push_back(Result.get()); |
| 7567 | } |
| 7568 | if (!getDerived().AlwaysRebuild() && !ExprsChanged) |
| 7569 | return S; |
| 7570 | |
| 7571 | // Go through the clobbers. |
| 7572 | for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) |
| 7573 | Clobbers.push_back(S->getClobberStringLiteral(I)); |
| 7574 | |
| 7575 | // No need to transform the asm string literal. |
| 7576 | AsmString = S->getAsmString(); |
| 7577 | return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(), |
| 7578 | S->isVolatile(), S->getNumOutputs(), |
| 7579 | S->getNumInputs(), Names.data(), |
| 7580 | Constraints, Exprs, AsmString.get(), |
| 7581 | Clobbers, S->getNumLabels(), |
| 7582 | S->getRParenLoc()); |
| 7583 | } |
| 7584 | |
| 7585 | template<typename Derived> |
| 7586 | StmtResult |
| 7587 | TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { |
| 7588 | ArrayRef<Token> AsmToks = |
| 7589 | llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); |
| 7590 | |
| 7591 | bool HadError = false, HadChange = false; |
| 7592 | |
| 7593 | ArrayRef<Expr*> SrcExprs = S->getAllExprs(); |
| 7594 | SmallVector<Expr*, 8> TransformedExprs; |
| 7595 | TransformedExprs.reserve(SrcExprs.size()); |
| 7596 | for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) { |
| 7597 | ExprResult Result = getDerived().TransformExpr(SrcExprs[i]); |
| 7598 | if (!Result.isUsable()) { |
| 7599 | HadError = true; |
| 7600 | } else { |
| 7601 | HadChange |= (Result.get() != SrcExprs[i]); |
| 7602 | TransformedExprs.push_back(Result.get()); |
| 7603 | } |
| 7604 | } |
| 7605 | |
| 7606 | if (HadError) return StmtError(); |
| 7607 | if (!HadChange && !getDerived().AlwaysRebuild()) |
| 7608 | return Owned(S); |
| 7609 | |
| 7610 | return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), |
| 7611 | AsmToks, S->getAsmString(), |
| 7612 | S->getNumOutputs(), S->getNumInputs(), |
| 7613 | S->getAllConstraints(), S->getClobbers(), |
| 7614 | TransformedExprs, S->getEndLoc()); |
| 7615 | } |
| 7616 | |
| 7617 | // C++ Coroutines TS |
| 7618 | |
| 7619 | template<typename Derived> |
| 7620 | StmtResult |
| 7621 | TreeTransform<Derived>::TransformCoroutineBodyStmt(CoroutineBodyStmt *S) { |
| 7622 | auto *ScopeInfo = SemaRef.getCurFunction(); |
| 7623 | auto *FD = cast<FunctionDecl>(SemaRef.CurContext); |
| 7624 | assert(FD && ScopeInfo && !ScopeInfo->CoroutinePromise && |
| 7625 | ScopeInfo->NeedsCoroutineSuspends && |
| 7626 | ScopeInfo->CoroutineSuspends.first == nullptr && |
| 7627 | ScopeInfo->CoroutineSuspends.second == nullptr && |
| 7628 | "expected clean scope info" ); |
| 7629 | |
| 7630 | // Set that we have (possibly-invalid) suspend points before we do anything |
| 7631 | // that may fail. |
| 7632 | ScopeInfo->setNeedsCoroutineSuspends(false); |
| 7633 | |
| 7634 | // We re-build the coroutine promise object (and the coroutine parameters its |
| 7635 | // type and constructor depend on) based on the types used in our current |
| 7636 | // function. We must do so, and set it on the current FunctionScopeInfo, |
| 7637 | // before attempting to transform the other parts of the coroutine body |
| 7638 | // statement, such as the implicit suspend statements (because those |
| 7639 | // statements reference the FunctionScopeInfo::CoroutinePromise). |
| 7640 | if (!SemaRef.buildCoroutineParameterMoves(FD->getLocation())) |
| 7641 | return StmtError(); |
| 7642 | auto *Promise = SemaRef.buildCoroutinePromise(FD->getLocation()); |
| 7643 | if (!Promise) |
| 7644 | return StmtError(); |
| 7645 | getDerived().transformedLocalDecl(S->getPromiseDecl(), {Promise}); |
| 7646 | ScopeInfo->CoroutinePromise = Promise; |
| 7647 | |
| 7648 | // Transform the implicit coroutine statements constructed using dependent |
| 7649 | // types during the previous parse: initial and final suspensions, the return |
| 7650 | // object, and others. We also transform the coroutine function's body. |
| 7651 | StmtResult InitSuspend = getDerived().TransformStmt(S->getInitSuspendStmt()); |
| 7652 | if (InitSuspend.isInvalid()) |
| 7653 | return StmtError(); |
| 7654 | StmtResult FinalSuspend = |
| 7655 | getDerived().TransformStmt(S->getFinalSuspendStmt()); |
| 7656 | if (FinalSuspend.isInvalid() || |
| 7657 | !SemaRef.checkFinalSuspendNoThrow(FinalSuspend.get())) |
| 7658 | return StmtError(); |
| 7659 | ScopeInfo->setCoroutineSuspends(InitSuspend.get(), FinalSuspend.get()); |
| 7660 | assert(isa<Expr>(InitSuspend.get()) && isa<Expr>(FinalSuspend.get())); |
| 7661 | |
| 7662 | StmtResult BodyRes = getDerived().TransformStmt(S->getBody()); |
| 7663 | if (BodyRes.isInvalid()) |
| 7664 | return StmtError(); |
| 7665 | |
| 7666 | CoroutineStmtBuilder Builder(SemaRef, *FD, *ScopeInfo, BodyRes.get()); |
| 7667 | if (Builder.isInvalid()) |
| 7668 | return StmtError(); |
| 7669 | |
| 7670 | Expr *ReturnObject = S->getReturnValueInit(); |
| 7671 | assert(ReturnObject && "the return object is expected to be valid" ); |
| 7672 | ExprResult Res = getDerived().TransformInitializer(ReturnObject, |
| 7673 | /*NoCopyInit*/ false); |
| 7674 | if (Res.isInvalid()) |
| 7675 | return StmtError(); |
| 7676 | Builder.ReturnValue = Res.get(); |
| 7677 | |
| 7678 | // If during the previous parse the coroutine still had a dependent promise |
| 7679 | // statement, we may need to build some implicit coroutine statements |
| 7680 | // (such as exception and fallthrough handlers) for the first time. |
| 7681 | if (S->hasDependentPromiseType()) { |
| 7682 | // We can only build these statements, however, if the current promise type |
| 7683 | // is not dependent. |
| 7684 | if (!Promise->getType()->isDependentType()) { |
| 7685 | assert(!S->getFallthroughHandler() && !S->getExceptionHandler() && |
| 7686 | !S->getReturnStmtOnAllocFailure() && !S->getDeallocate() && |
| 7687 | "these nodes should not have been built yet" ); |
| 7688 | if (!Builder.buildDependentStatements()) |
| 7689 | return StmtError(); |
| 7690 | } |
| 7691 | } else { |
| 7692 | if (auto *OnFallthrough = S->getFallthroughHandler()) { |
| 7693 | StmtResult Res = getDerived().TransformStmt(OnFallthrough); |
| 7694 | if (Res.isInvalid()) |
| 7695 | return StmtError(); |
| 7696 | Builder.OnFallthrough = Res.get(); |
| 7697 | } |
| 7698 | |
| 7699 | if (auto *OnException = S->getExceptionHandler()) { |
| 7700 | StmtResult Res = getDerived().TransformStmt(OnException); |
| 7701 | if (Res.isInvalid()) |
| 7702 | return StmtError(); |
| 7703 | Builder.OnException = Res.get(); |
| 7704 | } |
| 7705 | |
| 7706 | if (auto *OnAllocFailure = S->getReturnStmtOnAllocFailure()) { |
| 7707 | StmtResult Res = getDerived().TransformStmt(OnAllocFailure); |
| 7708 | if (Res.isInvalid()) |
| 7709 | return StmtError(); |
| 7710 | Builder.ReturnStmtOnAllocFailure = Res.get(); |
| 7711 | } |
| 7712 | |
| 7713 | // Transform any additional statements we may have already built |
| 7714 | assert(S->getAllocate() && S->getDeallocate() && |
| 7715 | "allocation and deallocation calls must already be built" ); |
| 7716 | ExprResult AllocRes = getDerived().TransformExpr(S->getAllocate()); |
| 7717 | if (AllocRes.isInvalid()) |
| 7718 | return StmtError(); |
| 7719 | Builder.Allocate = AllocRes.get(); |
| 7720 | |
| 7721 | ExprResult DeallocRes = getDerived().TransformExpr(S->getDeallocate()); |
| 7722 | if (DeallocRes.isInvalid()) |
| 7723 | return StmtError(); |
| 7724 | Builder.Deallocate = DeallocRes.get(); |
| 7725 | |
| 7726 | assert(S->getResultDecl() && "ResultDecl must already be built" ); |
| 7727 | StmtResult ResultDecl = getDerived().TransformStmt(S->getResultDecl()); |
| 7728 | if (ResultDecl.isInvalid()) |
| 7729 | return StmtError(); |
| 7730 | Builder.ResultDecl = ResultDecl.get(); |
| 7731 | |
| 7732 | if (auto *ReturnStmt = S->getReturnStmt()) { |
| 7733 | StmtResult Res = getDerived().TransformStmt(ReturnStmt); |
| 7734 | if (Res.isInvalid()) |
| 7735 | return StmtError(); |
| 7736 | Builder.ReturnStmt = Res.get(); |
| 7737 | } |
| 7738 | } |
| 7739 | |
| 7740 | return getDerived().RebuildCoroutineBodyStmt(Builder); |
| 7741 | } |
| 7742 | |
| 7743 | template<typename Derived> |
| 7744 | StmtResult |
| 7745 | TreeTransform<Derived>::TransformCoreturnStmt(CoreturnStmt *S) { |
| 7746 | ExprResult Result = getDerived().TransformInitializer(S->getOperand(), |
| 7747 | /*NotCopyInit*/false); |
| 7748 | if (Result.isInvalid()) |
| 7749 | return StmtError(); |
| 7750 | |
| 7751 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7752 | // context or if the promise type has changed. |
| 7753 | return getDerived().RebuildCoreturnStmt(S->getKeywordLoc(), Result.get(), |
| 7754 | S->isImplicit()); |
| 7755 | } |
| 7756 | |
| 7757 | template<typename Derived> |
| 7758 | ExprResult |
| 7759 | TreeTransform<Derived>::TransformCoawaitExpr(CoawaitExpr *E) { |
| 7760 | ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 7761 | /*NotCopyInit*/false); |
| 7762 | if (Result.isInvalid()) |
| 7763 | return ExprError(); |
| 7764 | |
| 7765 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7766 | // context or if the promise type has changed. |
| 7767 | return getDerived().RebuildCoawaitExpr(E->getKeywordLoc(), Result.get(), |
| 7768 | E->isImplicit()); |
| 7769 | } |
| 7770 | |
| 7771 | template <typename Derived> |
| 7772 | ExprResult |
| 7773 | TreeTransform<Derived>::TransformDependentCoawaitExpr(DependentCoawaitExpr *E) { |
| 7774 | ExprResult OperandResult = getDerived().TransformInitializer(E->getOperand(), |
| 7775 | /*NotCopyInit*/ false); |
| 7776 | if (OperandResult.isInvalid()) |
| 7777 | return ExprError(); |
| 7778 | |
| 7779 | ExprResult LookupResult = getDerived().TransformUnresolvedLookupExpr( |
| 7780 | E->getOperatorCoawaitLookup()); |
| 7781 | |
| 7782 | if (LookupResult.isInvalid()) |
| 7783 | return ExprError(); |
| 7784 | |
| 7785 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7786 | // context or if the promise type has changed. |
| 7787 | return getDerived().RebuildDependentCoawaitExpr( |
| 7788 | E->getKeywordLoc(), OperandResult.get(), |
| 7789 | cast<UnresolvedLookupExpr>(LookupResult.get())); |
| 7790 | } |
| 7791 | |
| 7792 | template<typename Derived> |
| 7793 | ExprResult |
| 7794 | TreeTransform<Derived>::TransformCoyieldExpr(CoyieldExpr *E) { |
| 7795 | ExprResult Result = getDerived().TransformInitializer(E->getOperand(), |
| 7796 | /*NotCopyInit*/false); |
| 7797 | if (Result.isInvalid()) |
| 7798 | return ExprError(); |
| 7799 | |
| 7800 | // Always rebuild; we don't know if this needs to be injected into a new |
| 7801 | // context or if the promise type has changed. |
| 7802 | return getDerived().RebuildCoyieldExpr(E->getKeywordLoc(), Result.get()); |
| 7803 | } |
| 7804 | |
| 7805 | // Objective-C Statements. |
| 7806 | |
| 7807 | template<typename Derived> |
| 7808 | StmtResult |
| 7809 | TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { |
| 7810 | // Transform the body of the @try. |
| 7811 | StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); |
| 7812 | if (TryBody.isInvalid()) |
| 7813 | return StmtError(); |
| 7814 | |
| 7815 | // Transform the @catch statements (if present). |
| 7816 | bool AnyCatchChanged = false; |
| 7817 | SmallVector<Stmt*, 8> CatchStmts; |
| 7818 | for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { |
| 7819 | StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); |
| 7820 | if (Catch.isInvalid()) |
| 7821 | return StmtError(); |
| 7822 | if (Catch.get() != S->getCatchStmt(I)) |
| 7823 | AnyCatchChanged = true; |
| 7824 | CatchStmts.push_back(Catch.get()); |
| 7825 | } |
| 7826 | |
| 7827 | // Transform the @finally statement (if present). |
| 7828 | StmtResult Finally; |
| 7829 | if (S->getFinallyStmt()) { |
| 7830 | Finally = getDerived().TransformStmt(S->getFinallyStmt()); |
| 7831 | if (Finally.isInvalid()) |
| 7832 | return StmtError(); |
| 7833 | } |
| 7834 | |
| 7835 | // If nothing changed, just retain this statement. |
| 7836 | if (!getDerived().AlwaysRebuild() && |
| 7837 | TryBody.get() == S->getTryBody() && |
| 7838 | !AnyCatchChanged && |
| 7839 | Finally.get() == S->getFinallyStmt()) |
| 7840 | return S; |
| 7841 | |
| 7842 | // Build a new statement. |
| 7843 | return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), |
| 7844 | CatchStmts, Finally.get()); |
| 7845 | } |
| 7846 | |
| 7847 | template<typename Derived> |
| 7848 | StmtResult |
| 7849 | TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { |
| 7850 | // Transform the @catch parameter, if there is one. |
| 7851 | VarDecl *Var = nullptr; |
| 7852 | if (VarDecl *FromVar = S->getCatchParamDecl()) { |
| 7853 | TypeSourceInfo *TSInfo = nullptr; |
| 7854 | if (FromVar->getTypeSourceInfo()) { |
| 7855 | TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); |
| 7856 | if (!TSInfo) |
| 7857 | return StmtError(); |
| 7858 | } |
| 7859 | |
| 7860 | QualType T; |
| 7861 | if (TSInfo) |
| 7862 | T = TSInfo->getType(); |
| 7863 | else { |
| 7864 | T = getDerived().TransformType(FromVar->getType()); |
| 7865 | if (T.isNull()) |
| 7866 | return StmtError(); |
| 7867 | } |
| 7868 | |
| 7869 | Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); |
| 7870 | if (!Var) |
| 7871 | return StmtError(); |
| 7872 | } |
| 7873 | |
| 7874 | StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); |
| 7875 | if (Body.isInvalid()) |
| 7876 | return StmtError(); |
| 7877 | |
| 7878 | return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), |
| 7879 | S->getRParenLoc(), |
| 7880 | Var, Body.get()); |
| 7881 | } |
| 7882 | |
| 7883 | template<typename Derived> |
| 7884 | StmtResult |
| 7885 | TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { |
| 7886 | // Transform the body. |
| 7887 | StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); |
| 7888 | if (Body.isInvalid()) |
| 7889 | return StmtError(); |
| 7890 | |
| 7891 | // If nothing changed, just retain this statement. |
| 7892 | if (!getDerived().AlwaysRebuild() && |
| 7893 | Body.get() == S->getFinallyBody()) |
| 7894 | return S; |
| 7895 | |
| 7896 | // Build a new statement. |
| 7897 | return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), |
| 7898 | Body.get()); |
| 7899 | } |
| 7900 | |
| 7901 | template<typename Derived> |
| 7902 | StmtResult |
| 7903 | TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { |
| 7904 | ExprResult Operand; |
| 7905 | if (S->getThrowExpr()) { |
| 7906 | Operand = getDerived().TransformExpr(S->getThrowExpr()); |
| 7907 | if (Operand.isInvalid()) |
| 7908 | return StmtError(); |
| 7909 | } |
| 7910 | |
| 7911 | if (!getDerived().AlwaysRebuild() && |
| 7912 | Operand.get() == S->getThrowExpr()) |
| 7913 | return S; |
| 7914 | |
| 7915 | return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); |
| 7916 | } |
| 7917 | |
| 7918 | template<typename Derived> |
| 7919 | StmtResult |
| 7920 | TreeTransform<Derived>::TransformObjCAtSynchronizedStmt( |
| 7921 | ObjCAtSynchronizedStmt *S) { |
| 7922 | // Transform the object we are locking. |
| 7923 | ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); |
| 7924 | if (Object.isInvalid()) |
| 7925 | return StmtError(); |
| 7926 | Object = |
| 7927 | getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), |
| 7928 | Object.get()); |
| 7929 | if (Object.isInvalid()) |
| 7930 | return StmtError(); |
| 7931 | |
| 7932 | // Transform the body. |
| 7933 | StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); |
| 7934 | if (Body.isInvalid()) |
| 7935 | return StmtError(); |
| 7936 | |
| 7937 | // If nothing change, just retain the current statement. |
| 7938 | if (!getDerived().AlwaysRebuild() && |
| 7939 | Object.get() == S->getSynchExpr() && |
| 7940 | Body.get() == S->getSynchBody()) |
| 7941 | return S; |
| 7942 | |
| 7943 | // Build a new statement. |
| 7944 | return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), |
| 7945 | Object.get(), Body.get()); |
| 7946 | } |
| 7947 | |
| 7948 | template<typename Derived> |
| 7949 | StmtResult |
| 7950 | TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( |
| 7951 | ObjCAutoreleasePoolStmt *S) { |
| 7952 | // Transform the body. |
| 7953 | StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); |
| 7954 | if (Body.isInvalid()) |
| 7955 | return StmtError(); |
| 7956 | |
| 7957 | // If nothing changed, just retain this statement. |
| 7958 | if (!getDerived().AlwaysRebuild() && |
| 7959 | Body.get() == S->getSubStmt()) |
| 7960 | return S; |
| 7961 | |
| 7962 | // Build a new statement. |
| 7963 | return getDerived().RebuildObjCAutoreleasePoolStmt( |
| 7964 | S->getAtLoc(), Body.get()); |
| 7965 | } |
| 7966 | |
| 7967 | template<typename Derived> |
| 7968 | StmtResult |
| 7969 | TreeTransform<Derived>::TransformObjCForCollectionStmt( |
| 7970 | ObjCForCollectionStmt *S) { |
| 7971 | // Transform the element statement. |
| 7972 | StmtResult Element = |
| 7973 | getDerived().TransformStmt(S->getElement(), SDK_NotDiscarded); |
| 7974 | if (Element.isInvalid()) |
| 7975 | return StmtError(); |
| 7976 | |
| 7977 | // Transform the collection expression. |
| 7978 | ExprResult Collection = getDerived().TransformExpr(S->getCollection()); |
| 7979 | if (Collection.isInvalid()) |
| 7980 | return StmtError(); |
| 7981 | |
| 7982 | // Transform the body. |
| 7983 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 7984 | if (Body.isInvalid()) |
| 7985 | return StmtError(); |
| 7986 | |
| 7987 | // If nothing changed, just retain this statement. |
| 7988 | if (!getDerived().AlwaysRebuild() && |
| 7989 | Element.get() == S->getElement() && |
| 7990 | Collection.get() == S->getCollection() && |
| 7991 | Body.get() == S->getBody()) |
| 7992 | return S; |
| 7993 | |
| 7994 | // Build a new statement. |
| 7995 | return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), |
| 7996 | Element.get(), |
| 7997 | Collection.get(), |
| 7998 | S->getRParenLoc(), |
| 7999 | Body.get()); |
| 8000 | } |
| 8001 | |
| 8002 | template <typename Derived> |
| 8003 | StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { |
| 8004 | // Transform the exception declaration, if any. |
| 8005 | VarDecl *Var = nullptr; |
| 8006 | if (VarDecl *ExceptionDecl = S->getExceptionDecl()) { |
| 8007 | TypeSourceInfo *T = |
| 8008 | getDerived().TransformType(ExceptionDecl->getTypeSourceInfo()); |
| 8009 | if (!T) |
| 8010 | return StmtError(); |
| 8011 | |
| 8012 | Var = getDerived().RebuildExceptionDecl( |
| 8013 | ExceptionDecl, T, ExceptionDecl->getInnerLocStart(), |
| 8014 | ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier()); |
| 8015 | if (!Var || Var->isInvalidDecl()) |
| 8016 | return StmtError(); |
| 8017 | } |
| 8018 | |
| 8019 | // Transform the actual exception handler. |
| 8020 | StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); |
| 8021 | if (Handler.isInvalid()) |
| 8022 | return StmtError(); |
| 8023 | |
| 8024 | if (!getDerived().AlwaysRebuild() && !Var && |
| 8025 | Handler.get() == S->getHandlerBlock()) |
| 8026 | return S; |
| 8027 | |
| 8028 | return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get()); |
| 8029 | } |
| 8030 | |
| 8031 | template <typename Derived> |
| 8032 | StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { |
| 8033 | // Transform the try block itself. |
| 8034 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 8035 | if (TryBlock.isInvalid()) |
| 8036 | return StmtError(); |
| 8037 | |
| 8038 | // Transform the handlers. |
| 8039 | bool HandlerChanged = false; |
| 8040 | SmallVector<Stmt *, 8> Handlers; |
| 8041 | for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { |
| 8042 | StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I)); |
| 8043 | if (Handler.isInvalid()) |
| 8044 | return StmtError(); |
| 8045 | |
| 8046 | HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); |
| 8047 | Handlers.push_back(Handler.getAs<Stmt>()); |
| 8048 | } |
| 8049 | |
| 8050 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 8051 | !HandlerChanged) |
| 8052 | return S; |
| 8053 | |
| 8054 | return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), |
| 8055 | Handlers); |
| 8056 | } |
| 8057 | |
| 8058 | template<typename Derived> |
| 8059 | StmtResult |
| 8060 | TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { |
| 8061 | StmtResult Init = |
| 8062 | S->getInit() ? getDerived().TransformStmt(S->getInit()) : StmtResult(); |
| 8063 | if (Init.isInvalid()) |
| 8064 | return StmtError(); |
| 8065 | |
| 8066 | StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); |
| 8067 | if (Range.isInvalid()) |
| 8068 | return StmtError(); |
| 8069 | |
| 8070 | StmtResult Begin = getDerived().TransformStmt(S->getBeginStmt()); |
| 8071 | if (Begin.isInvalid()) |
| 8072 | return StmtError(); |
| 8073 | StmtResult End = getDerived().TransformStmt(S->getEndStmt()); |
| 8074 | if (End.isInvalid()) |
| 8075 | return StmtError(); |
| 8076 | |
| 8077 | ExprResult Cond = getDerived().TransformExpr(S->getCond()); |
| 8078 | if (Cond.isInvalid()) |
| 8079 | return StmtError(); |
| 8080 | if (Cond.get()) |
| 8081 | Cond = SemaRef.CheckBooleanCondition(S->getColonLoc(), Cond.get()); |
| 8082 | if (Cond.isInvalid()) |
| 8083 | return StmtError(); |
| 8084 | if (Cond.get()) |
| 8085 | Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get()); |
| 8086 | |
| 8087 | ExprResult Inc = getDerived().TransformExpr(S->getInc()); |
| 8088 | if (Inc.isInvalid()) |
| 8089 | return StmtError(); |
| 8090 | if (Inc.get()) |
| 8091 | Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get()); |
| 8092 | |
| 8093 | StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); |
| 8094 | if (LoopVar.isInvalid()) |
| 8095 | return StmtError(); |
| 8096 | |
| 8097 | StmtResult NewStmt = S; |
| 8098 | if (getDerived().AlwaysRebuild() || |
| 8099 | Init.get() != S->getInit() || |
| 8100 | Range.get() != S->getRangeStmt() || |
| 8101 | Begin.get() != S->getBeginStmt() || |
| 8102 | End.get() != S->getEndStmt() || |
| 8103 | Cond.get() != S->getCond() || |
| 8104 | Inc.get() != S->getInc() || |
| 8105 | LoopVar.get() != S->getLoopVarStmt()) { |
| 8106 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 8107 | S->getCoawaitLoc(), Init.get(), |
| 8108 | S->getColonLoc(), Range.get(), |
| 8109 | Begin.get(), End.get(), |
| 8110 | Cond.get(), |
| 8111 | Inc.get(), LoopVar.get(), |
| 8112 | S->getRParenLoc()); |
| 8113 | if (NewStmt.isInvalid() && LoopVar.get() != S->getLoopVarStmt()) { |
| 8114 | // Might not have attached any initializer to the loop variable. |
| 8115 | getSema().ActOnInitializerError( |
| 8116 | cast<DeclStmt>(LoopVar.get())->getSingleDecl()); |
| 8117 | return StmtError(); |
| 8118 | } |
| 8119 | } |
| 8120 | |
| 8121 | StmtResult Body = getDerived().TransformStmt(S->getBody()); |
| 8122 | if (Body.isInvalid()) |
| 8123 | return StmtError(); |
| 8124 | |
| 8125 | // Body has changed but we didn't rebuild the for-range statement. Rebuild |
| 8126 | // it now so we have a new statement to attach the body to. |
| 8127 | if (Body.get() != S->getBody() && NewStmt.get() == S) { |
| 8128 | NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), |
| 8129 | S->getCoawaitLoc(), Init.get(), |
| 8130 | S->getColonLoc(), Range.get(), |
| 8131 | Begin.get(), End.get(), |
| 8132 | Cond.get(), |
| 8133 | Inc.get(), LoopVar.get(), |
| 8134 | S->getRParenLoc()); |
| 8135 | if (NewStmt.isInvalid()) |
| 8136 | return StmtError(); |
| 8137 | } |
| 8138 | |
| 8139 | if (NewStmt.get() == S) |
| 8140 | return S; |
| 8141 | |
| 8142 | return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); |
| 8143 | } |
| 8144 | |
| 8145 | template<typename Derived> |
| 8146 | StmtResult |
| 8147 | TreeTransform<Derived>::TransformMSDependentExistsStmt( |
| 8148 | MSDependentExistsStmt *S) { |
| 8149 | // Transform the nested-name-specifier, if any. |
| 8150 | NestedNameSpecifierLoc QualifierLoc; |
| 8151 | if (S->getQualifierLoc()) { |
| 8152 | QualifierLoc |
| 8153 | = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); |
| 8154 | if (!QualifierLoc) |
| 8155 | return StmtError(); |
| 8156 | } |
| 8157 | |
| 8158 | // Transform the declaration name. |
| 8159 | DeclarationNameInfo NameInfo = S->getNameInfo(); |
| 8160 | if (NameInfo.getName()) { |
| 8161 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 8162 | if (!NameInfo.getName()) |
| 8163 | return StmtError(); |
| 8164 | } |
| 8165 | |
| 8166 | // Check whether anything changed. |
| 8167 | if (!getDerived().AlwaysRebuild() && |
| 8168 | QualifierLoc == S->getQualifierLoc() && |
| 8169 | NameInfo.getName() == S->getNameInfo().getName()) |
| 8170 | return S; |
| 8171 | |
| 8172 | // Determine whether this name exists, if we can. |
| 8173 | CXXScopeSpec SS; |
| 8174 | SS.Adopt(QualifierLoc); |
| 8175 | bool Dependent = false; |
| 8176 | switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) { |
| 8177 | case Sema::IER_Exists: |
| 8178 | if (S->isIfExists()) |
| 8179 | break; |
| 8180 | |
| 8181 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 8182 | |
| 8183 | case Sema::IER_DoesNotExist: |
| 8184 | if (S->isIfNotExists()) |
| 8185 | break; |
| 8186 | |
| 8187 | return new (getSema().Context) NullStmt(S->getKeywordLoc()); |
| 8188 | |
| 8189 | case Sema::IER_Dependent: |
| 8190 | Dependent = true; |
| 8191 | break; |
| 8192 | |
| 8193 | case Sema::IER_Error: |
| 8194 | return StmtError(); |
| 8195 | } |
| 8196 | |
| 8197 | // We need to continue with the instantiation, so do so now. |
| 8198 | StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); |
| 8199 | if (SubStmt.isInvalid()) |
| 8200 | return StmtError(); |
| 8201 | |
| 8202 | // If we have resolved the name, just transform to the substatement. |
| 8203 | if (!Dependent) |
| 8204 | return SubStmt; |
| 8205 | |
| 8206 | // The name is still dependent, so build a dependent expression again. |
| 8207 | return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), |
| 8208 | S->isIfExists(), |
| 8209 | QualifierLoc, |
| 8210 | NameInfo, |
| 8211 | SubStmt.get()); |
| 8212 | } |
| 8213 | |
| 8214 | template<typename Derived> |
| 8215 | ExprResult |
| 8216 | TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) { |
| 8217 | NestedNameSpecifierLoc QualifierLoc; |
| 8218 | if (E->getQualifierLoc()) { |
| 8219 | QualifierLoc |
| 8220 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 8221 | if (!QualifierLoc) |
| 8222 | return ExprError(); |
| 8223 | } |
| 8224 | |
| 8225 | MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>( |
| 8226 | getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl())); |
| 8227 | if (!PD) |
| 8228 | return ExprError(); |
| 8229 | |
| 8230 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 8231 | if (Base.isInvalid()) |
| 8232 | return ExprError(); |
| 8233 | |
| 8234 | return new (SemaRef.getASTContext()) |
| 8235 | MSPropertyRefExpr(Base.get(), PD, E->isArrow(), |
| 8236 | SemaRef.getASTContext().PseudoObjectTy, VK_LValue, |
| 8237 | QualifierLoc, E->getMemberLoc()); |
| 8238 | } |
| 8239 | |
| 8240 | template <typename Derived> |
| 8241 | ExprResult TreeTransform<Derived>::TransformMSPropertySubscriptExpr( |
| 8242 | MSPropertySubscriptExpr *E) { |
| 8243 | auto BaseRes = getDerived().TransformExpr(E->getBase()); |
| 8244 | if (BaseRes.isInvalid()) |
| 8245 | return ExprError(); |
| 8246 | auto IdxRes = getDerived().TransformExpr(E->getIdx()); |
| 8247 | if (IdxRes.isInvalid()) |
| 8248 | return ExprError(); |
| 8249 | |
| 8250 | if (!getDerived().AlwaysRebuild() && |
| 8251 | BaseRes.get() == E->getBase() && |
| 8252 | IdxRes.get() == E->getIdx()) |
| 8253 | return E; |
| 8254 | |
| 8255 | return getDerived().RebuildArraySubscriptExpr( |
| 8256 | BaseRes.get(), SourceLocation(), IdxRes.get(), E->getRBracketLoc()); |
| 8257 | } |
| 8258 | |
| 8259 | template <typename Derived> |
| 8260 | StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { |
| 8261 | StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock()); |
| 8262 | if (TryBlock.isInvalid()) |
| 8263 | return StmtError(); |
| 8264 | |
| 8265 | StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); |
| 8266 | if (Handler.isInvalid()) |
| 8267 | return StmtError(); |
| 8268 | |
| 8269 | if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() && |
| 8270 | Handler.get() == S->getHandler()) |
| 8271 | return S; |
| 8272 | |
| 8273 | return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(), |
| 8274 | TryBlock.get(), Handler.get()); |
| 8275 | } |
| 8276 | |
| 8277 | template <typename Derived> |
| 8278 | StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { |
| 8279 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
| 8280 | if (Block.isInvalid()) |
| 8281 | return StmtError(); |
| 8282 | |
| 8283 | return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get()); |
| 8284 | } |
| 8285 | |
| 8286 | template <typename Derived> |
| 8287 | StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { |
| 8288 | ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); |
| 8289 | if (FilterExpr.isInvalid()) |
| 8290 | return StmtError(); |
| 8291 | |
| 8292 | StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock()); |
| 8293 | if (Block.isInvalid()) |
| 8294 | return StmtError(); |
| 8295 | |
| 8296 | return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(), |
| 8297 | Block.get()); |
| 8298 | } |
| 8299 | |
| 8300 | template <typename Derived> |
| 8301 | StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { |
| 8302 | if (isa<SEHFinallyStmt>(Handler)) |
| 8303 | return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); |
| 8304 | else |
| 8305 | return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); |
| 8306 | } |
| 8307 | |
| 8308 | template<typename Derived> |
| 8309 | StmtResult |
| 8310 | TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) { |
| 8311 | return S; |
| 8312 | } |
| 8313 | |
| 8314 | //===----------------------------------------------------------------------===// |
| 8315 | // OpenMP directive transformation |
| 8316 | //===----------------------------------------------------------------------===// |
| 8317 | template <typename Derived> |
| 8318 | StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective( |
| 8319 | OMPExecutableDirective *D) { |
| 8320 | |
| 8321 | // Transform the clauses |
| 8322 | llvm::SmallVector<OMPClause *, 16> TClauses; |
| 8323 | ArrayRef<OMPClause *> Clauses = D->clauses(); |
| 8324 | TClauses.reserve(Clauses.size()); |
| 8325 | for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end(); |
| 8326 | I != E; ++I) { |
| 8327 | if (*I) { |
| 8328 | getDerived().getSema().StartOpenMPClause((*I)->getClauseKind()); |
| 8329 | OMPClause *Clause = getDerived().TransformOMPClause(*I); |
| 8330 | getDerived().getSema().EndOpenMPClause(); |
| 8331 | if (Clause) |
| 8332 | TClauses.push_back(Clause); |
| 8333 | } else { |
| 8334 | TClauses.push_back(nullptr); |
| 8335 | } |
| 8336 | } |
| 8337 | StmtResult AssociatedStmt; |
| 8338 | if (D->hasAssociatedStmt() && D->getAssociatedStmt()) { |
| 8339 | getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(), |
| 8340 | /*CurScope=*/nullptr); |
| 8341 | StmtResult Body; |
| 8342 | { |
| 8343 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 8344 | Stmt *CS; |
| 8345 | if (D->getDirectiveKind() == OMPD_atomic || |
| 8346 | D->getDirectiveKind() == OMPD_critical || |
| 8347 | D->getDirectiveKind() == OMPD_section || |
| 8348 | D->getDirectiveKind() == OMPD_master) |
| 8349 | CS = D->getAssociatedStmt(); |
| 8350 | else |
| 8351 | CS = D->getInnermostCapturedStmt()->getCapturedStmt(); |
| 8352 | Body = getDerived().TransformStmt(CS); |
| 8353 | } |
| 8354 | AssociatedStmt = |
| 8355 | getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses); |
| 8356 | if (AssociatedStmt.isInvalid()) { |
| 8357 | return StmtError(); |
| 8358 | } |
| 8359 | } |
| 8360 | if (TClauses.size() != Clauses.size()) { |
| 8361 | return StmtError(); |
| 8362 | } |
| 8363 | |
| 8364 | // Transform directive name for 'omp critical' directive. |
| 8365 | DeclarationNameInfo DirName; |
| 8366 | if (D->getDirectiveKind() == OMPD_critical) { |
| 8367 | DirName = cast<OMPCriticalDirective>(D)->getDirectiveName(); |
| 8368 | DirName = getDerived().TransformDeclarationNameInfo(DirName); |
| 8369 | } |
| 8370 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
| 8371 | if (D->getDirectiveKind() == OMPD_cancellation_point) { |
| 8372 | CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion(); |
| 8373 | } else if (D->getDirectiveKind() == OMPD_cancel) { |
| 8374 | CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion(); |
| 8375 | } |
| 8376 | |
| 8377 | return getDerived().RebuildOMPExecutableDirective( |
| 8378 | D->getDirectiveKind(), DirName, CancelRegion, TClauses, |
| 8379 | AssociatedStmt.get(), D->getBeginLoc(), D->getEndLoc()); |
| 8380 | } |
| 8381 | |
| 8382 | template <typename Derived> |
| 8383 | StmtResult |
| 8384 | TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) { |
| 8385 | DeclarationNameInfo DirName; |
| 8386 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr, |
| 8387 | D->getBeginLoc()); |
| 8388 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8389 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8390 | return Res; |
| 8391 | } |
| 8392 | |
| 8393 | template <typename Derived> |
| 8394 | StmtResult |
| 8395 | TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) { |
| 8396 | DeclarationNameInfo DirName; |
| 8397 | getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr, |
| 8398 | D->getBeginLoc()); |
| 8399 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8400 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8401 | return Res; |
| 8402 | } |
| 8403 | |
| 8404 | template <typename Derived> |
| 8405 | StmtResult |
| 8406 | TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) { |
| 8407 | DeclarationNameInfo DirName; |
| 8408 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr, |
| 8409 | D->getBeginLoc()); |
| 8410 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8411 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8412 | return Res; |
| 8413 | } |
| 8414 | |
| 8415 | template <typename Derived> |
| 8416 | StmtResult |
| 8417 | TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) { |
| 8418 | DeclarationNameInfo DirName; |
| 8419 | getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr, |
| 8420 | D->getBeginLoc()); |
| 8421 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8422 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8423 | return Res; |
| 8424 | } |
| 8425 | |
| 8426 | template <typename Derived> |
| 8427 | StmtResult |
| 8428 | TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) { |
| 8429 | DeclarationNameInfo DirName; |
| 8430 | getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr, |
| 8431 | D->getBeginLoc()); |
| 8432 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8433 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8434 | return Res; |
| 8435 | } |
| 8436 | |
| 8437 | template <typename Derived> |
| 8438 | StmtResult |
| 8439 | TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) { |
| 8440 | DeclarationNameInfo DirName; |
| 8441 | getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr, |
| 8442 | D->getBeginLoc()); |
| 8443 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8444 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8445 | return Res; |
| 8446 | } |
| 8447 | |
| 8448 | template <typename Derived> |
| 8449 | StmtResult |
| 8450 | TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) { |
| 8451 | DeclarationNameInfo DirName; |
| 8452 | getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr, |
| 8453 | D->getBeginLoc()); |
| 8454 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8455 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8456 | return Res; |
| 8457 | } |
| 8458 | |
| 8459 | template <typename Derived> |
| 8460 | StmtResult |
| 8461 | TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) { |
| 8462 | DeclarationNameInfo DirName; |
| 8463 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr, |
| 8464 | D->getBeginLoc()); |
| 8465 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8466 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8467 | return Res; |
| 8468 | } |
| 8469 | |
| 8470 | template <typename Derived> |
| 8471 | StmtResult |
| 8472 | TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) { |
| 8473 | getDerived().getSema().StartOpenMPDSABlock( |
| 8474 | OMPD_critical, D->getDirectiveName(), nullptr, D->getBeginLoc()); |
| 8475 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8476 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8477 | return Res; |
| 8478 | } |
| 8479 | |
| 8480 | template <typename Derived> |
| 8481 | StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective( |
| 8482 | OMPParallelForDirective *D) { |
| 8483 | DeclarationNameInfo DirName; |
| 8484 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName, |
| 8485 | nullptr, D->getBeginLoc()); |
| 8486 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8487 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8488 | return Res; |
| 8489 | } |
| 8490 | |
| 8491 | template <typename Derived> |
| 8492 | StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective( |
| 8493 | OMPParallelForSimdDirective *D) { |
| 8494 | DeclarationNameInfo DirName; |
| 8495 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName, |
| 8496 | nullptr, D->getBeginLoc()); |
| 8497 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8498 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8499 | return Res; |
| 8500 | } |
| 8501 | |
| 8502 | template <typename Derived> |
| 8503 | StmtResult TreeTransform<Derived>::TransformOMPParallelMasterDirective( |
| 8504 | OMPParallelMasterDirective *D) { |
| 8505 | DeclarationNameInfo DirName; |
| 8506 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_master, DirName, |
| 8507 | nullptr, D->getBeginLoc()); |
| 8508 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8509 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8510 | return Res; |
| 8511 | } |
| 8512 | |
| 8513 | template <typename Derived> |
| 8514 | StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective( |
| 8515 | OMPParallelSectionsDirective *D) { |
| 8516 | DeclarationNameInfo DirName; |
| 8517 | getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName, |
| 8518 | nullptr, D->getBeginLoc()); |
| 8519 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8520 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8521 | return Res; |
| 8522 | } |
| 8523 | |
| 8524 | template <typename Derived> |
| 8525 | StmtResult |
| 8526 | TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) { |
| 8527 | DeclarationNameInfo DirName; |
| 8528 | getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr, |
| 8529 | D->getBeginLoc()); |
| 8530 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8531 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8532 | return Res; |
| 8533 | } |
| 8534 | |
| 8535 | template <typename Derived> |
| 8536 | StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective( |
| 8537 | OMPTaskyieldDirective *D) { |
| 8538 | DeclarationNameInfo DirName; |
| 8539 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr, |
| 8540 | D->getBeginLoc()); |
| 8541 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8542 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8543 | return Res; |
| 8544 | } |
| 8545 | |
| 8546 | template <typename Derived> |
| 8547 | StmtResult |
| 8548 | TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) { |
| 8549 | DeclarationNameInfo DirName; |
| 8550 | getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr, |
| 8551 | D->getBeginLoc()); |
| 8552 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8553 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8554 | return Res; |
| 8555 | } |
| 8556 | |
| 8557 | template <typename Derived> |
| 8558 | StmtResult |
| 8559 | TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) { |
| 8560 | DeclarationNameInfo DirName; |
| 8561 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr, |
| 8562 | D->getBeginLoc()); |
| 8563 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8564 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8565 | return Res; |
| 8566 | } |
| 8567 | |
| 8568 | template <typename Derived> |
| 8569 | StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective( |
| 8570 | OMPTaskgroupDirective *D) { |
| 8571 | DeclarationNameInfo DirName; |
| 8572 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr, |
| 8573 | D->getBeginLoc()); |
| 8574 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8575 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8576 | return Res; |
| 8577 | } |
| 8578 | |
| 8579 | template <typename Derived> |
| 8580 | StmtResult |
| 8581 | TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) { |
| 8582 | DeclarationNameInfo DirName; |
| 8583 | getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr, |
| 8584 | D->getBeginLoc()); |
| 8585 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8586 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8587 | return Res; |
| 8588 | } |
| 8589 | |
| 8590 | template <typename Derived> |
| 8591 | StmtResult |
| 8592 | TreeTransform<Derived>::TransformOMPDepobjDirective(OMPDepobjDirective *D) { |
| 8593 | DeclarationNameInfo DirName; |
| 8594 | getDerived().getSema().StartOpenMPDSABlock(OMPD_depobj, DirName, nullptr, |
| 8595 | D->getBeginLoc()); |
| 8596 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8597 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8598 | return Res; |
| 8599 | } |
| 8600 | |
| 8601 | template <typename Derived> |
| 8602 | StmtResult |
| 8603 | TreeTransform<Derived>::TransformOMPScanDirective(OMPScanDirective *D) { |
| 8604 | DeclarationNameInfo DirName; |
| 8605 | getDerived().getSema().StartOpenMPDSABlock(OMPD_scan, DirName, nullptr, |
| 8606 | D->getBeginLoc()); |
| 8607 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8608 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8609 | return Res; |
| 8610 | } |
| 8611 | |
| 8612 | template <typename Derived> |
| 8613 | StmtResult |
| 8614 | TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) { |
| 8615 | DeclarationNameInfo DirName; |
| 8616 | getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr, |
| 8617 | D->getBeginLoc()); |
| 8618 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8619 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8620 | return Res; |
| 8621 | } |
| 8622 | |
| 8623 | template <typename Derived> |
| 8624 | StmtResult |
| 8625 | TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) { |
| 8626 | DeclarationNameInfo DirName; |
| 8627 | getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr, |
| 8628 | D->getBeginLoc()); |
| 8629 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8630 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8631 | return Res; |
| 8632 | } |
| 8633 | |
| 8634 | template <typename Derived> |
| 8635 | StmtResult |
| 8636 | TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) { |
| 8637 | DeclarationNameInfo DirName; |
| 8638 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr, |
| 8639 | D->getBeginLoc()); |
| 8640 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8641 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8642 | return Res; |
| 8643 | } |
| 8644 | |
| 8645 | template <typename Derived> |
| 8646 | StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective( |
| 8647 | OMPTargetDataDirective *D) { |
| 8648 | DeclarationNameInfo DirName; |
| 8649 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr, |
| 8650 | D->getBeginLoc()); |
| 8651 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8652 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8653 | return Res; |
| 8654 | } |
| 8655 | |
| 8656 | template <typename Derived> |
| 8657 | StmtResult TreeTransform<Derived>::TransformOMPTargetEnterDataDirective( |
| 8658 | OMPTargetEnterDataDirective *D) { |
| 8659 | DeclarationNameInfo DirName; |
| 8660 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_enter_data, DirName, |
| 8661 | nullptr, D->getBeginLoc()); |
| 8662 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8663 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8664 | return Res; |
| 8665 | } |
| 8666 | |
| 8667 | template <typename Derived> |
| 8668 | StmtResult TreeTransform<Derived>::TransformOMPTargetExitDataDirective( |
| 8669 | OMPTargetExitDataDirective *D) { |
| 8670 | DeclarationNameInfo DirName; |
| 8671 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_exit_data, DirName, |
| 8672 | nullptr, D->getBeginLoc()); |
| 8673 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8674 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8675 | return Res; |
| 8676 | } |
| 8677 | |
| 8678 | template <typename Derived> |
| 8679 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelDirective( |
| 8680 | OMPTargetParallelDirective *D) { |
| 8681 | DeclarationNameInfo DirName; |
| 8682 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel, DirName, |
| 8683 | nullptr, D->getBeginLoc()); |
| 8684 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8685 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8686 | return Res; |
| 8687 | } |
| 8688 | |
| 8689 | template <typename Derived> |
| 8690 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForDirective( |
| 8691 | OMPTargetParallelForDirective *D) { |
| 8692 | DeclarationNameInfo DirName; |
| 8693 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_parallel_for, DirName, |
| 8694 | nullptr, D->getBeginLoc()); |
| 8695 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8696 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8697 | return Res; |
| 8698 | } |
| 8699 | |
| 8700 | template <typename Derived> |
| 8701 | StmtResult TreeTransform<Derived>::TransformOMPTargetUpdateDirective( |
| 8702 | OMPTargetUpdateDirective *D) { |
| 8703 | DeclarationNameInfo DirName; |
| 8704 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_update, DirName, |
| 8705 | nullptr, D->getBeginLoc()); |
| 8706 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8707 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8708 | return Res; |
| 8709 | } |
| 8710 | |
| 8711 | template <typename Derived> |
| 8712 | StmtResult |
| 8713 | TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) { |
| 8714 | DeclarationNameInfo DirName; |
| 8715 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr, |
| 8716 | D->getBeginLoc()); |
| 8717 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8718 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8719 | return Res; |
| 8720 | } |
| 8721 | |
| 8722 | template <typename Derived> |
| 8723 | StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective( |
| 8724 | OMPCancellationPointDirective *D) { |
| 8725 | DeclarationNameInfo DirName; |
| 8726 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName, |
| 8727 | nullptr, D->getBeginLoc()); |
| 8728 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8729 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8730 | return Res; |
| 8731 | } |
| 8732 | |
| 8733 | template <typename Derived> |
| 8734 | StmtResult |
| 8735 | TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) { |
| 8736 | DeclarationNameInfo DirName; |
| 8737 | getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr, |
| 8738 | D->getBeginLoc()); |
| 8739 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8740 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8741 | return Res; |
| 8742 | } |
| 8743 | |
| 8744 | template <typename Derived> |
| 8745 | StmtResult |
| 8746 | TreeTransform<Derived>::TransformOMPTaskLoopDirective(OMPTaskLoopDirective *D) { |
| 8747 | DeclarationNameInfo DirName; |
| 8748 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop, DirName, nullptr, |
| 8749 | D->getBeginLoc()); |
| 8750 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8751 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8752 | return Res; |
| 8753 | } |
| 8754 | |
| 8755 | template <typename Derived> |
| 8756 | StmtResult TreeTransform<Derived>::TransformOMPTaskLoopSimdDirective( |
| 8757 | OMPTaskLoopSimdDirective *D) { |
| 8758 | DeclarationNameInfo DirName; |
| 8759 | getDerived().getSema().StartOpenMPDSABlock(OMPD_taskloop_simd, DirName, |
| 8760 | nullptr, D->getBeginLoc()); |
| 8761 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8762 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8763 | return Res; |
| 8764 | } |
| 8765 | |
| 8766 | template <typename Derived> |
| 8767 | StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopDirective( |
| 8768 | OMPMasterTaskLoopDirective *D) { |
| 8769 | DeclarationNameInfo DirName; |
| 8770 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop, DirName, |
| 8771 | nullptr, D->getBeginLoc()); |
| 8772 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8773 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8774 | return Res; |
| 8775 | } |
| 8776 | |
| 8777 | template <typename Derived> |
| 8778 | StmtResult TreeTransform<Derived>::TransformOMPMasterTaskLoopSimdDirective( |
| 8779 | OMPMasterTaskLoopSimdDirective *D) { |
| 8780 | DeclarationNameInfo DirName; |
| 8781 | getDerived().getSema().StartOpenMPDSABlock(OMPD_master_taskloop_simd, DirName, |
| 8782 | nullptr, D->getBeginLoc()); |
| 8783 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8784 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8785 | return Res; |
| 8786 | } |
| 8787 | |
| 8788 | template <typename Derived> |
| 8789 | StmtResult TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopDirective( |
| 8790 | OMPParallelMasterTaskLoopDirective *D) { |
| 8791 | DeclarationNameInfo DirName; |
| 8792 | getDerived().getSema().StartOpenMPDSABlock( |
| 8793 | OMPD_parallel_master_taskloop, DirName, nullptr, D->getBeginLoc()); |
| 8794 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8795 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8796 | return Res; |
| 8797 | } |
| 8798 | |
| 8799 | template <typename Derived> |
| 8800 | StmtResult |
| 8801 | TreeTransform<Derived>::TransformOMPParallelMasterTaskLoopSimdDirective( |
| 8802 | OMPParallelMasterTaskLoopSimdDirective *D) { |
| 8803 | DeclarationNameInfo DirName; |
| 8804 | getDerived().getSema().StartOpenMPDSABlock( |
| 8805 | OMPD_parallel_master_taskloop_simd, DirName, nullptr, D->getBeginLoc()); |
| 8806 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8807 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8808 | return Res; |
| 8809 | } |
| 8810 | |
| 8811 | template <typename Derived> |
| 8812 | StmtResult TreeTransform<Derived>::TransformOMPDistributeDirective( |
| 8813 | OMPDistributeDirective *D) { |
| 8814 | DeclarationNameInfo DirName; |
| 8815 | getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute, DirName, nullptr, |
| 8816 | D->getBeginLoc()); |
| 8817 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8818 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8819 | return Res; |
| 8820 | } |
| 8821 | |
| 8822 | template <typename Derived> |
| 8823 | StmtResult TreeTransform<Derived>::TransformOMPDistributeParallelForDirective( |
| 8824 | OMPDistributeParallelForDirective *D) { |
| 8825 | DeclarationNameInfo DirName; |
| 8826 | getDerived().getSema().StartOpenMPDSABlock( |
| 8827 | OMPD_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| 8828 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8829 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8830 | return Res; |
| 8831 | } |
| 8832 | |
| 8833 | template <typename Derived> |
| 8834 | StmtResult |
| 8835 | TreeTransform<Derived>::TransformOMPDistributeParallelForSimdDirective( |
| 8836 | OMPDistributeParallelForSimdDirective *D) { |
| 8837 | DeclarationNameInfo DirName; |
| 8838 | getDerived().getSema().StartOpenMPDSABlock( |
| 8839 | OMPD_distribute_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| 8840 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8841 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8842 | return Res; |
| 8843 | } |
| 8844 | |
| 8845 | template <typename Derived> |
| 8846 | StmtResult TreeTransform<Derived>::TransformOMPDistributeSimdDirective( |
| 8847 | OMPDistributeSimdDirective *D) { |
| 8848 | DeclarationNameInfo DirName; |
| 8849 | getDerived().getSema().StartOpenMPDSABlock(OMPD_distribute_simd, DirName, |
| 8850 | nullptr, D->getBeginLoc()); |
| 8851 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8852 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8853 | return Res; |
| 8854 | } |
| 8855 | |
| 8856 | template <typename Derived> |
| 8857 | StmtResult TreeTransform<Derived>::TransformOMPTargetParallelForSimdDirective( |
| 8858 | OMPTargetParallelForSimdDirective *D) { |
| 8859 | DeclarationNameInfo DirName; |
| 8860 | getDerived().getSema().StartOpenMPDSABlock( |
| 8861 | OMPD_target_parallel_for_simd, DirName, nullptr, D->getBeginLoc()); |
| 8862 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8863 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8864 | return Res; |
| 8865 | } |
| 8866 | |
| 8867 | template <typename Derived> |
| 8868 | StmtResult TreeTransform<Derived>::TransformOMPTargetSimdDirective( |
| 8869 | OMPTargetSimdDirective *D) { |
| 8870 | DeclarationNameInfo DirName; |
| 8871 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_simd, DirName, nullptr, |
| 8872 | D->getBeginLoc()); |
| 8873 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8874 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8875 | return Res; |
| 8876 | } |
| 8877 | |
| 8878 | template <typename Derived> |
| 8879 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeDirective( |
| 8880 | OMPTeamsDistributeDirective *D) { |
| 8881 | DeclarationNameInfo DirName; |
| 8882 | getDerived().getSema().StartOpenMPDSABlock(OMPD_teams_distribute, DirName, |
| 8883 | nullptr, D->getBeginLoc()); |
| 8884 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8885 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8886 | return Res; |
| 8887 | } |
| 8888 | |
| 8889 | template <typename Derived> |
| 8890 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeSimdDirective( |
| 8891 | OMPTeamsDistributeSimdDirective *D) { |
| 8892 | DeclarationNameInfo DirName; |
| 8893 | getDerived().getSema().StartOpenMPDSABlock( |
| 8894 | OMPD_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| 8895 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8896 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8897 | return Res; |
| 8898 | } |
| 8899 | |
| 8900 | template <typename Derived> |
| 8901 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForSimdDirective( |
| 8902 | OMPTeamsDistributeParallelForSimdDirective *D) { |
| 8903 | DeclarationNameInfo DirName; |
| 8904 | getDerived().getSema().StartOpenMPDSABlock( |
| 8905 | OMPD_teams_distribute_parallel_for_simd, DirName, nullptr, |
| 8906 | D->getBeginLoc()); |
| 8907 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8908 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8909 | return Res; |
| 8910 | } |
| 8911 | |
| 8912 | template <typename Derived> |
| 8913 | StmtResult TreeTransform<Derived>::TransformOMPTeamsDistributeParallelForDirective( |
| 8914 | OMPTeamsDistributeParallelForDirective *D) { |
| 8915 | DeclarationNameInfo DirName; |
| 8916 | getDerived().getSema().StartOpenMPDSABlock( |
| 8917 | OMPD_teams_distribute_parallel_for, DirName, nullptr, D->getBeginLoc()); |
| 8918 | StmtResult Res = getDerived().TransformOMPExecutableDirective(D); |
| 8919 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8920 | return Res; |
| 8921 | } |
| 8922 | |
| 8923 | template <typename Derived> |
| 8924 | StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDirective( |
| 8925 | OMPTargetTeamsDirective *D) { |
| 8926 | DeclarationNameInfo DirName; |
| 8927 | getDerived().getSema().StartOpenMPDSABlock(OMPD_target_teams, DirName, |
| 8928 | nullptr, D->getBeginLoc()); |
| 8929 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8930 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8931 | return Res; |
| 8932 | } |
| 8933 | |
| 8934 | template <typename Derived> |
| 8935 | StmtResult TreeTransform<Derived>::TransformOMPTargetTeamsDistributeDirective( |
| 8936 | OMPTargetTeamsDistributeDirective *D) { |
| 8937 | DeclarationNameInfo DirName; |
| 8938 | getDerived().getSema().StartOpenMPDSABlock( |
| 8939 | OMPD_target_teams_distribute, DirName, nullptr, D->getBeginLoc()); |
| 8940 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8941 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8942 | return Res; |
| 8943 | } |
| 8944 | |
| 8945 | template <typename Derived> |
| 8946 | StmtResult |
| 8947 | TreeTransform<Derived>::TransformOMPTargetTeamsDistributeParallelForDirective( |
| 8948 | OMPTargetTeamsDistributeParallelForDirective *D) { |
| 8949 | DeclarationNameInfo DirName; |
| 8950 | getDerived().getSema().StartOpenMPDSABlock( |
| 8951 | OMPD_target_teams_distribute_parallel_for, DirName, nullptr, |
| 8952 | D->getBeginLoc()); |
| 8953 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8954 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8955 | return Res; |
| 8956 | } |
| 8957 | |
| 8958 | template <typename Derived> |
| 8959 | StmtResult TreeTransform<Derived>:: |
| 8960 | TransformOMPTargetTeamsDistributeParallelForSimdDirective( |
| 8961 | OMPTargetTeamsDistributeParallelForSimdDirective *D) { |
| 8962 | DeclarationNameInfo DirName; |
| 8963 | getDerived().getSema().StartOpenMPDSABlock( |
| 8964 | OMPD_target_teams_distribute_parallel_for_simd, DirName, nullptr, |
| 8965 | D->getBeginLoc()); |
| 8966 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8967 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8968 | return Res; |
| 8969 | } |
| 8970 | |
| 8971 | template <typename Derived> |
| 8972 | StmtResult |
| 8973 | TreeTransform<Derived>::TransformOMPTargetTeamsDistributeSimdDirective( |
| 8974 | OMPTargetTeamsDistributeSimdDirective *D) { |
| 8975 | DeclarationNameInfo DirName; |
| 8976 | getDerived().getSema().StartOpenMPDSABlock( |
| 8977 | OMPD_target_teams_distribute_simd, DirName, nullptr, D->getBeginLoc()); |
| 8978 | auto Res = getDerived().TransformOMPExecutableDirective(D); |
| 8979 | getDerived().getSema().EndOpenMPDSABlock(Res.get()); |
| 8980 | return Res; |
| 8981 | } |
| 8982 | |
| 8983 | |
| 8984 | //===----------------------------------------------------------------------===// |
| 8985 | // OpenMP clause transformation |
| 8986 | //===----------------------------------------------------------------------===// |
| 8987 | template <typename Derived> |
| 8988 | OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) { |
| 8989 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 8990 | if (Cond.isInvalid()) |
| 8991 | return nullptr; |
| 8992 | return getDerived().RebuildOMPIfClause( |
| 8993 | C->getNameModifier(), Cond.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 8994 | C->getNameModifierLoc(), C->getColonLoc(), C->getEndLoc()); |
| 8995 | } |
| 8996 | |
| 8997 | template <typename Derived> |
| 8998 | OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) { |
| 8999 | ExprResult Cond = getDerived().TransformExpr(C->getCondition()); |
| 9000 | if (Cond.isInvalid()) |
| 9001 | return nullptr; |
| 9002 | return getDerived().RebuildOMPFinalClause(Cond.get(), C->getBeginLoc(), |
| 9003 | C->getLParenLoc(), C->getEndLoc()); |
| 9004 | } |
| 9005 | |
| 9006 | template <typename Derived> |
| 9007 | OMPClause * |
| 9008 | TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) { |
| 9009 | ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads()); |
| 9010 | if (NumThreads.isInvalid()) |
| 9011 | return nullptr; |
| 9012 | return getDerived().RebuildOMPNumThreadsClause( |
| 9013 | NumThreads.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9014 | } |
| 9015 | |
| 9016 | template <typename Derived> |
| 9017 | OMPClause * |
| 9018 | TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) { |
| 9019 | ExprResult E = getDerived().TransformExpr(C->getSafelen()); |
| 9020 | if (E.isInvalid()) |
| 9021 | return nullptr; |
| 9022 | return getDerived().RebuildOMPSafelenClause( |
| 9023 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9024 | } |
| 9025 | |
| 9026 | template <typename Derived> |
| 9027 | OMPClause * |
| 9028 | TreeTransform<Derived>::TransformOMPAllocatorClause(OMPAllocatorClause *C) { |
| 9029 | ExprResult E = getDerived().TransformExpr(C->getAllocator()); |
| 9030 | if (E.isInvalid()) |
| 9031 | return nullptr; |
| 9032 | return getDerived().RebuildOMPAllocatorClause( |
| 9033 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9034 | } |
| 9035 | |
| 9036 | template <typename Derived> |
| 9037 | OMPClause * |
| 9038 | TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) { |
| 9039 | ExprResult E = getDerived().TransformExpr(C->getSimdlen()); |
| 9040 | if (E.isInvalid()) |
| 9041 | return nullptr; |
| 9042 | return getDerived().RebuildOMPSimdlenClause( |
| 9043 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9044 | } |
| 9045 | |
| 9046 | template <typename Derived> |
| 9047 | OMPClause * |
| 9048 | TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) { |
| 9049 | ExprResult E = getDerived().TransformExpr(C->getNumForLoops()); |
| 9050 | if (E.isInvalid()) |
| 9051 | return nullptr; |
| 9052 | return getDerived().RebuildOMPCollapseClause( |
| 9053 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9054 | } |
| 9055 | |
| 9056 | template <typename Derived> |
| 9057 | OMPClause * |
| 9058 | TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) { |
| 9059 | return getDerived().RebuildOMPDefaultClause( |
| 9060 | C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getBeginLoc(), |
| 9061 | C->getLParenLoc(), C->getEndLoc()); |
| 9062 | } |
| 9063 | |
| 9064 | template <typename Derived> |
| 9065 | OMPClause * |
| 9066 | TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) { |
| 9067 | return getDerived().RebuildOMPProcBindClause( |
| 9068 | C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getBeginLoc(), |
| 9069 | C->getLParenLoc(), C->getEndLoc()); |
| 9070 | } |
| 9071 | |
| 9072 | template <typename Derived> |
| 9073 | OMPClause * |
| 9074 | TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) { |
| 9075 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 9076 | if (E.isInvalid()) |
| 9077 | return nullptr; |
| 9078 | return getDerived().RebuildOMPScheduleClause( |
| 9079 | C->getFirstScheduleModifier(), C->getSecondScheduleModifier(), |
| 9080 | C->getScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 9081 | C->getFirstScheduleModifierLoc(), C->getSecondScheduleModifierLoc(), |
| 9082 | C->getScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); |
| 9083 | } |
| 9084 | |
| 9085 | template <typename Derived> |
| 9086 | OMPClause * |
| 9087 | TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) { |
| 9088 | ExprResult E; |
| 9089 | if (auto *Num = C->getNumForLoops()) { |
| 9090 | E = getDerived().TransformExpr(Num); |
| 9091 | if (E.isInvalid()) |
| 9092 | return nullptr; |
| 9093 | } |
| 9094 | return getDerived().RebuildOMPOrderedClause(C->getBeginLoc(), C->getEndLoc(), |
| 9095 | C->getLParenLoc(), E.get()); |
| 9096 | } |
| 9097 | |
| 9098 | template <typename Derived> |
| 9099 | OMPClause * |
| 9100 | TreeTransform<Derived>::TransformOMPDetachClause(OMPDetachClause *C) { |
| 9101 | ExprResult E; |
| 9102 | if (Expr *Evt = C->getEventHandler()) { |
| 9103 | E = getDerived().TransformExpr(Evt); |
| 9104 | if (E.isInvalid()) |
| 9105 | return nullptr; |
| 9106 | } |
| 9107 | return getDerived().RebuildOMPDetachClause(E.get(), C->getBeginLoc(), |
| 9108 | C->getLParenLoc(), C->getEndLoc()); |
| 9109 | } |
| 9110 | |
| 9111 | template <typename Derived> |
| 9112 | OMPClause * |
| 9113 | TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) { |
| 9114 | // No need to rebuild this clause, no template-dependent parameters. |
| 9115 | return C; |
| 9116 | } |
| 9117 | |
| 9118 | template <typename Derived> |
| 9119 | OMPClause * |
| 9120 | TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) { |
| 9121 | // No need to rebuild this clause, no template-dependent parameters. |
| 9122 | return C; |
| 9123 | } |
| 9124 | |
| 9125 | template <typename Derived> |
| 9126 | OMPClause * |
| 9127 | TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) { |
| 9128 | // No need to rebuild this clause, no template-dependent parameters. |
| 9129 | return C; |
| 9130 | } |
| 9131 | |
| 9132 | template <typename Derived> |
| 9133 | OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) { |
| 9134 | // No need to rebuild this clause, no template-dependent parameters. |
| 9135 | return C; |
| 9136 | } |
| 9137 | |
| 9138 | template <typename Derived> |
| 9139 | OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) { |
| 9140 | // No need to rebuild this clause, no template-dependent parameters. |
| 9141 | return C; |
| 9142 | } |
| 9143 | |
| 9144 | template <typename Derived> |
| 9145 | OMPClause * |
| 9146 | TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) { |
| 9147 | // No need to rebuild this clause, no template-dependent parameters. |
| 9148 | return C; |
| 9149 | } |
| 9150 | |
| 9151 | template <typename Derived> |
| 9152 | OMPClause * |
| 9153 | TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) { |
| 9154 | // No need to rebuild this clause, no template-dependent parameters. |
| 9155 | return C; |
| 9156 | } |
| 9157 | |
| 9158 | template <typename Derived> |
| 9159 | OMPClause * |
| 9160 | TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) { |
| 9161 | // No need to rebuild this clause, no template-dependent parameters. |
| 9162 | return C; |
| 9163 | } |
| 9164 | |
| 9165 | template <typename Derived> |
| 9166 | OMPClause * |
| 9167 | TreeTransform<Derived>::TransformOMPAcqRelClause(OMPAcqRelClause *C) { |
| 9168 | // No need to rebuild this clause, no template-dependent parameters. |
| 9169 | return C; |
| 9170 | } |
| 9171 | |
| 9172 | template <typename Derived> |
| 9173 | OMPClause * |
| 9174 | TreeTransform<Derived>::TransformOMPAcquireClause(OMPAcquireClause *C) { |
| 9175 | // No need to rebuild this clause, no template-dependent parameters. |
| 9176 | return C; |
| 9177 | } |
| 9178 | |
| 9179 | template <typename Derived> |
| 9180 | OMPClause * |
| 9181 | TreeTransform<Derived>::TransformOMPReleaseClause(OMPReleaseClause *C) { |
| 9182 | // No need to rebuild this clause, no template-dependent parameters. |
| 9183 | return C; |
| 9184 | } |
| 9185 | |
| 9186 | template <typename Derived> |
| 9187 | OMPClause * |
| 9188 | TreeTransform<Derived>::TransformOMPRelaxedClause(OMPRelaxedClause *C) { |
| 9189 | // No need to rebuild this clause, no template-dependent parameters. |
| 9190 | return C; |
| 9191 | } |
| 9192 | |
| 9193 | template <typename Derived> |
| 9194 | OMPClause * |
| 9195 | TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) { |
| 9196 | // No need to rebuild this clause, no template-dependent parameters. |
| 9197 | return C; |
| 9198 | } |
| 9199 | |
| 9200 | template <typename Derived> |
| 9201 | OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) { |
| 9202 | // No need to rebuild this clause, no template-dependent parameters. |
| 9203 | return C; |
| 9204 | } |
| 9205 | |
| 9206 | template <typename Derived> |
| 9207 | OMPClause * |
| 9208 | TreeTransform<Derived>::TransformOMPNogroupClause(OMPNogroupClause *C) { |
| 9209 | // No need to rebuild this clause, no template-dependent parameters. |
| 9210 | return C; |
| 9211 | } |
| 9212 | |
| 9213 | template <typename Derived> |
| 9214 | OMPClause * |
| 9215 | TreeTransform<Derived>::TransformOMPDestroyClause(OMPDestroyClause *C) { |
| 9216 | // No need to rebuild this clause, no template-dependent parameters. |
| 9217 | return C; |
| 9218 | } |
| 9219 | |
| 9220 | template <typename Derived> |
| 9221 | OMPClause *TreeTransform<Derived>::TransformOMPUnifiedAddressClause( |
| 9222 | OMPUnifiedAddressClause *C) { |
| 9223 | llvm_unreachable("unified_address clause cannot appear in dependent context" ); |
| 9224 | } |
| 9225 | |
| 9226 | template <typename Derived> |
| 9227 | OMPClause *TreeTransform<Derived>::TransformOMPUnifiedSharedMemoryClause( |
| 9228 | OMPUnifiedSharedMemoryClause *C) { |
| 9229 | llvm_unreachable( |
| 9230 | "unified_shared_memory clause cannot appear in dependent context" ); |
| 9231 | } |
| 9232 | |
| 9233 | template <typename Derived> |
| 9234 | OMPClause *TreeTransform<Derived>::TransformOMPReverseOffloadClause( |
| 9235 | OMPReverseOffloadClause *C) { |
| 9236 | llvm_unreachable("reverse_offload clause cannot appear in dependent context" ); |
| 9237 | } |
| 9238 | |
| 9239 | template <typename Derived> |
| 9240 | OMPClause *TreeTransform<Derived>::TransformOMPDynamicAllocatorsClause( |
| 9241 | OMPDynamicAllocatorsClause *C) { |
| 9242 | llvm_unreachable( |
| 9243 | "dynamic_allocators clause cannot appear in dependent context" ); |
| 9244 | } |
| 9245 | |
| 9246 | template <typename Derived> |
| 9247 | OMPClause *TreeTransform<Derived>::TransformOMPAtomicDefaultMemOrderClause( |
| 9248 | OMPAtomicDefaultMemOrderClause *C) { |
| 9249 | llvm_unreachable( |
| 9250 | "atomic_default_mem_order clause cannot appear in dependent context" ); |
| 9251 | } |
| 9252 | |
| 9253 | template <typename Derived> |
| 9254 | OMPClause * |
| 9255 | TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) { |
| 9256 | llvm::SmallVector<Expr *, 16> Vars; |
| 9257 | Vars.reserve(C->varlist_size()); |
| 9258 | for (auto *VE : C->varlists()) { |
| 9259 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9260 | if (EVar.isInvalid()) |
| 9261 | return nullptr; |
| 9262 | Vars.push_back(EVar.get()); |
| 9263 | } |
| 9264 | return getDerived().RebuildOMPPrivateClause( |
| 9265 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9266 | } |
| 9267 | |
| 9268 | template <typename Derived> |
| 9269 | OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause( |
| 9270 | OMPFirstprivateClause *C) { |
| 9271 | llvm::SmallVector<Expr *, 16> Vars; |
| 9272 | Vars.reserve(C->varlist_size()); |
| 9273 | for (auto *VE : C->varlists()) { |
| 9274 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9275 | if (EVar.isInvalid()) |
| 9276 | return nullptr; |
| 9277 | Vars.push_back(EVar.get()); |
| 9278 | } |
| 9279 | return getDerived().RebuildOMPFirstprivateClause( |
| 9280 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9281 | } |
| 9282 | |
| 9283 | template <typename Derived> |
| 9284 | OMPClause * |
| 9285 | TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) { |
| 9286 | llvm::SmallVector<Expr *, 16> Vars; |
| 9287 | Vars.reserve(C->varlist_size()); |
| 9288 | for (auto *VE : C->varlists()) { |
| 9289 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9290 | if (EVar.isInvalid()) |
| 9291 | return nullptr; |
| 9292 | Vars.push_back(EVar.get()); |
| 9293 | } |
| 9294 | return getDerived().RebuildOMPLastprivateClause( |
| 9295 | Vars, C->getKind(), C->getKindLoc(), C->getColonLoc(), C->getBeginLoc(), |
| 9296 | C->getLParenLoc(), C->getEndLoc()); |
| 9297 | } |
| 9298 | |
| 9299 | template <typename Derived> |
| 9300 | OMPClause * |
| 9301 | TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) { |
| 9302 | llvm::SmallVector<Expr *, 16> Vars; |
| 9303 | Vars.reserve(C->varlist_size()); |
| 9304 | for (auto *VE : C->varlists()) { |
| 9305 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9306 | if (EVar.isInvalid()) |
| 9307 | return nullptr; |
| 9308 | Vars.push_back(EVar.get()); |
| 9309 | } |
| 9310 | return getDerived().RebuildOMPSharedClause(Vars, C->getBeginLoc(), |
| 9311 | C->getLParenLoc(), C->getEndLoc()); |
| 9312 | } |
| 9313 | |
| 9314 | template <typename Derived> |
| 9315 | OMPClause * |
| 9316 | TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) { |
| 9317 | llvm::SmallVector<Expr *, 16> Vars; |
| 9318 | Vars.reserve(C->varlist_size()); |
| 9319 | for (auto *VE : C->varlists()) { |
| 9320 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9321 | if (EVar.isInvalid()) |
| 9322 | return nullptr; |
| 9323 | Vars.push_back(EVar.get()); |
| 9324 | } |
| 9325 | CXXScopeSpec ReductionIdScopeSpec; |
| 9326 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 9327 | |
| 9328 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 9329 | if (NameInfo.getName()) { |
| 9330 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 9331 | if (!NameInfo.getName()) |
| 9332 | return nullptr; |
| 9333 | } |
| 9334 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 9335 | // The Scope boundary is a duplication of the previous decl. |
| 9336 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 9337 | for (auto *E : C->reduction_ops()) { |
| 9338 | // Transform all the decls. |
| 9339 | if (E) { |
| 9340 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 9341 | UnresolvedSet<8> Decls; |
| 9342 | for (auto *D : ULE->decls()) { |
| 9343 | NamedDecl *InstD = |
| 9344 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 9345 | Decls.addDecl(InstD, InstD->getAccess()); |
| 9346 | } |
| 9347 | UnresolvedReductions.push_back( |
| 9348 | UnresolvedLookupExpr::Create( |
| 9349 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 9350 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), |
| 9351 | NameInfo, /*ADL=*/true, ULE->isOverloaded(), |
| 9352 | Decls.begin(), Decls.end())); |
| 9353 | } else |
| 9354 | UnresolvedReductions.push_back(nullptr); |
| 9355 | } |
| 9356 | return getDerived().RebuildOMPReductionClause( |
| 9357 | Vars, C->getModifier(), C->getBeginLoc(), C->getLParenLoc(), |
| 9358 | C->getModifierLoc(), C->getColonLoc(), C->getEndLoc(), |
| 9359 | ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| 9360 | } |
| 9361 | |
| 9362 | template <typename Derived> |
| 9363 | OMPClause *TreeTransform<Derived>::TransformOMPTaskReductionClause( |
| 9364 | OMPTaskReductionClause *C) { |
| 9365 | llvm::SmallVector<Expr *, 16> Vars; |
| 9366 | Vars.reserve(C->varlist_size()); |
| 9367 | for (auto *VE : C->varlists()) { |
| 9368 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9369 | if (EVar.isInvalid()) |
| 9370 | return nullptr; |
| 9371 | Vars.push_back(EVar.get()); |
| 9372 | } |
| 9373 | CXXScopeSpec ReductionIdScopeSpec; |
| 9374 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 9375 | |
| 9376 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 9377 | if (NameInfo.getName()) { |
| 9378 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 9379 | if (!NameInfo.getName()) |
| 9380 | return nullptr; |
| 9381 | } |
| 9382 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 9383 | // The Scope boundary is a duplication of the previous decl. |
| 9384 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 9385 | for (auto *E : C->reduction_ops()) { |
| 9386 | // Transform all the decls. |
| 9387 | if (E) { |
| 9388 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 9389 | UnresolvedSet<8> Decls; |
| 9390 | for (auto *D : ULE->decls()) { |
| 9391 | NamedDecl *InstD = |
| 9392 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 9393 | Decls.addDecl(InstD, InstD->getAccess()); |
| 9394 | } |
| 9395 | UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 9396 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 9397 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 9398 | /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); |
| 9399 | } else |
| 9400 | UnresolvedReductions.push_back(nullptr); |
| 9401 | } |
| 9402 | return getDerived().RebuildOMPTaskReductionClause( |
| 9403 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| 9404 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| 9405 | } |
| 9406 | |
| 9407 | template <typename Derived> |
| 9408 | OMPClause * |
| 9409 | TreeTransform<Derived>::TransformOMPInReductionClause(OMPInReductionClause *C) { |
| 9410 | llvm::SmallVector<Expr *, 16> Vars; |
| 9411 | Vars.reserve(C->varlist_size()); |
| 9412 | for (auto *VE : C->varlists()) { |
| 9413 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9414 | if (EVar.isInvalid()) |
| 9415 | return nullptr; |
| 9416 | Vars.push_back(EVar.get()); |
| 9417 | } |
| 9418 | CXXScopeSpec ReductionIdScopeSpec; |
| 9419 | ReductionIdScopeSpec.Adopt(C->getQualifierLoc()); |
| 9420 | |
| 9421 | DeclarationNameInfo NameInfo = C->getNameInfo(); |
| 9422 | if (NameInfo.getName()) { |
| 9423 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 9424 | if (!NameInfo.getName()) |
| 9425 | return nullptr; |
| 9426 | } |
| 9427 | // Build a list of all UDR decls with the same names ranged by the Scopes. |
| 9428 | // The Scope boundary is a duplication of the previous decl. |
| 9429 | llvm::SmallVector<Expr *, 16> UnresolvedReductions; |
| 9430 | for (auto *E : C->reduction_ops()) { |
| 9431 | // Transform all the decls. |
| 9432 | if (E) { |
| 9433 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 9434 | UnresolvedSet<8> Decls; |
| 9435 | for (auto *D : ULE->decls()) { |
| 9436 | NamedDecl *InstD = |
| 9437 | cast<NamedDecl>(getDerived().TransformDecl(E->getExprLoc(), D)); |
| 9438 | Decls.addDecl(InstD, InstD->getAccess()); |
| 9439 | } |
| 9440 | UnresolvedReductions.push_back(UnresolvedLookupExpr::Create( |
| 9441 | SemaRef.Context, /*NamingClass=*/nullptr, |
| 9442 | ReductionIdScopeSpec.getWithLocInContext(SemaRef.Context), NameInfo, |
| 9443 | /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), Decls.end())); |
| 9444 | } else |
| 9445 | UnresolvedReductions.push_back(nullptr); |
| 9446 | } |
| 9447 | return getDerived().RebuildOMPInReductionClause( |
| 9448 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| 9449 | C->getEndLoc(), ReductionIdScopeSpec, NameInfo, UnresolvedReductions); |
| 9450 | } |
| 9451 | |
| 9452 | template <typename Derived> |
| 9453 | OMPClause * |
| 9454 | TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) { |
| 9455 | llvm::SmallVector<Expr *, 16> Vars; |
| 9456 | Vars.reserve(C->varlist_size()); |
| 9457 | for (auto *VE : C->varlists()) { |
| 9458 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9459 | if (EVar.isInvalid()) |
| 9460 | return nullptr; |
| 9461 | Vars.push_back(EVar.get()); |
| 9462 | } |
| 9463 | ExprResult Step = getDerived().TransformExpr(C->getStep()); |
| 9464 | if (Step.isInvalid()) |
| 9465 | return nullptr; |
| 9466 | return getDerived().RebuildOMPLinearClause( |
| 9467 | Vars, Step.get(), C->getBeginLoc(), C->getLParenLoc(), C->getModifier(), |
| 9468 | C->getModifierLoc(), C->getColonLoc(), C->getEndLoc()); |
| 9469 | } |
| 9470 | |
| 9471 | template <typename Derived> |
| 9472 | OMPClause * |
| 9473 | TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) { |
| 9474 | llvm::SmallVector<Expr *, 16> Vars; |
| 9475 | Vars.reserve(C->varlist_size()); |
| 9476 | for (auto *VE : C->varlists()) { |
| 9477 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9478 | if (EVar.isInvalid()) |
| 9479 | return nullptr; |
| 9480 | Vars.push_back(EVar.get()); |
| 9481 | } |
| 9482 | ExprResult Alignment = getDerived().TransformExpr(C->getAlignment()); |
| 9483 | if (Alignment.isInvalid()) |
| 9484 | return nullptr; |
| 9485 | return getDerived().RebuildOMPAlignedClause( |
| 9486 | Vars, Alignment.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 9487 | C->getColonLoc(), C->getEndLoc()); |
| 9488 | } |
| 9489 | |
| 9490 | template <typename Derived> |
| 9491 | OMPClause * |
| 9492 | TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) { |
| 9493 | llvm::SmallVector<Expr *, 16> Vars; |
| 9494 | Vars.reserve(C->varlist_size()); |
| 9495 | for (auto *VE : C->varlists()) { |
| 9496 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9497 | if (EVar.isInvalid()) |
| 9498 | return nullptr; |
| 9499 | Vars.push_back(EVar.get()); |
| 9500 | } |
| 9501 | return getDerived().RebuildOMPCopyinClause(Vars, C->getBeginLoc(), |
| 9502 | C->getLParenLoc(), C->getEndLoc()); |
| 9503 | } |
| 9504 | |
| 9505 | template <typename Derived> |
| 9506 | OMPClause * |
| 9507 | TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) { |
| 9508 | llvm::SmallVector<Expr *, 16> Vars; |
| 9509 | Vars.reserve(C->varlist_size()); |
| 9510 | for (auto *VE : C->varlists()) { |
| 9511 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9512 | if (EVar.isInvalid()) |
| 9513 | return nullptr; |
| 9514 | Vars.push_back(EVar.get()); |
| 9515 | } |
| 9516 | return getDerived().RebuildOMPCopyprivateClause( |
| 9517 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9518 | } |
| 9519 | |
| 9520 | template <typename Derived> |
| 9521 | OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) { |
| 9522 | llvm::SmallVector<Expr *, 16> Vars; |
| 9523 | Vars.reserve(C->varlist_size()); |
| 9524 | for (auto *VE : C->varlists()) { |
| 9525 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9526 | if (EVar.isInvalid()) |
| 9527 | return nullptr; |
| 9528 | Vars.push_back(EVar.get()); |
| 9529 | } |
| 9530 | return getDerived().RebuildOMPFlushClause(Vars, C->getBeginLoc(), |
| 9531 | C->getLParenLoc(), C->getEndLoc()); |
| 9532 | } |
| 9533 | |
| 9534 | template <typename Derived> |
| 9535 | OMPClause * |
| 9536 | TreeTransform<Derived>::TransformOMPDepobjClause(OMPDepobjClause *C) { |
| 9537 | ExprResult E = getDerived().TransformExpr(C->getDepobj()); |
| 9538 | if (E.isInvalid()) |
| 9539 | return nullptr; |
| 9540 | return getDerived().RebuildOMPDepobjClause(E.get(), C->getBeginLoc(), |
| 9541 | C->getLParenLoc(), C->getEndLoc()); |
| 9542 | } |
| 9543 | |
| 9544 | template <typename Derived> |
| 9545 | OMPClause * |
| 9546 | TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) { |
| 9547 | llvm::SmallVector<Expr *, 16> Vars; |
| 9548 | Expr *DepModifier = C->getModifier(); |
| 9549 | if (DepModifier) { |
| 9550 | ExprResult DepModRes = getDerived().TransformExpr(DepModifier); |
| 9551 | if (DepModRes.isInvalid()) |
| 9552 | return nullptr; |
| 9553 | DepModifier = DepModRes.get(); |
| 9554 | } |
| 9555 | Vars.reserve(C->varlist_size()); |
| 9556 | for (auto *VE : C->varlists()) { |
| 9557 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9558 | if (EVar.isInvalid()) |
| 9559 | return nullptr; |
| 9560 | Vars.push_back(EVar.get()); |
| 9561 | } |
| 9562 | return getDerived().RebuildOMPDependClause( |
| 9563 | DepModifier, C->getDependencyKind(), C->getDependencyLoc(), |
| 9564 | C->getColonLoc(), Vars, C->getBeginLoc(), C->getLParenLoc(), |
| 9565 | C->getEndLoc()); |
| 9566 | } |
| 9567 | |
| 9568 | template <typename Derived> |
| 9569 | OMPClause * |
| 9570 | TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) { |
| 9571 | ExprResult E = getDerived().TransformExpr(C->getDevice()); |
| 9572 | if (E.isInvalid()) |
| 9573 | return nullptr; |
| 9574 | return getDerived().RebuildOMPDeviceClause( |
| 9575 | C->getModifier(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 9576 | C->getModifierLoc(), C->getEndLoc()); |
| 9577 | } |
| 9578 | |
| 9579 | template <typename Derived, class T> |
| 9580 | bool transformOMPMappableExprListClause( |
| 9581 | TreeTransform<Derived> &TT, OMPMappableExprListClause<T> *C, |
| 9582 | llvm::SmallVectorImpl<Expr *> &Vars, CXXScopeSpec &MapperIdScopeSpec, |
| 9583 | DeclarationNameInfo &MapperIdInfo, |
| 9584 | llvm::SmallVectorImpl<Expr *> &UnresolvedMappers) { |
| 9585 | // Transform expressions in the list. |
| 9586 | Vars.reserve(C->varlist_size()); |
| 9587 | for (auto *VE : C->varlists()) { |
| 9588 | ExprResult EVar = TT.getDerived().TransformExpr(cast<Expr>(VE)); |
| 9589 | if (EVar.isInvalid()) |
| 9590 | return true; |
| 9591 | Vars.push_back(EVar.get()); |
| 9592 | } |
| 9593 | // Transform mapper scope specifier and identifier. |
| 9594 | NestedNameSpecifierLoc QualifierLoc; |
| 9595 | if (C->getMapperQualifierLoc()) { |
| 9596 | QualifierLoc = TT.getDerived().TransformNestedNameSpecifierLoc( |
| 9597 | C->getMapperQualifierLoc()); |
| 9598 | if (!QualifierLoc) |
| 9599 | return true; |
| 9600 | } |
| 9601 | MapperIdScopeSpec.Adopt(QualifierLoc); |
| 9602 | MapperIdInfo = C->getMapperIdInfo(); |
| 9603 | if (MapperIdInfo.getName()) { |
| 9604 | MapperIdInfo = TT.getDerived().TransformDeclarationNameInfo(MapperIdInfo); |
| 9605 | if (!MapperIdInfo.getName()) |
| 9606 | return true; |
| 9607 | } |
| 9608 | // Build a list of all candidate OMPDeclareMapperDecls, which is provided by |
| 9609 | // the previous user-defined mapper lookup in dependent environment. |
| 9610 | for (auto *E : C->mapperlists()) { |
| 9611 | // Transform all the decls. |
| 9612 | if (E) { |
| 9613 | auto *ULE = cast<UnresolvedLookupExpr>(E); |
| 9614 | UnresolvedSet<8> Decls; |
| 9615 | for (auto *D : ULE->decls()) { |
| 9616 | NamedDecl *InstD = |
| 9617 | cast<NamedDecl>(TT.getDerived().TransformDecl(E->getExprLoc(), D)); |
| 9618 | Decls.addDecl(InstD, InstD->getAccess()); |
| 9619 | } |
| 9620 | UnresolvedMappers.push_back(UnresolvedLookupExpr::Create( |
| 9621 | TT.getSema().Context, /*NamingClass=*/nullptr, |
| 9622 | MapperIdScopeSpec.getWithLocInContext(TT.getSema().Context), |
| 9623 | MapperIdInfo, /*ADL=*/true, ULE->isOverloaded(), Decls.begin(), |
| 9624 | Decls.end())); |
| 9625 | } else { |
| 9626 | UnresolvedMappers.push_back(nullptr); |
| 9627 | } |
| 9628 | } |
| 9629 | return false; |
| 9630 | } |
| 9631 | |
| 9632 | template <typename Derived> |
| 9633 | OMPClause *TreeTransform<Derived>::TransformOMPMapClause(OMPMapClause *C) { |
| 9634 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9635 | llvm::SmallVector<Expr *, 16> Vars; |
| 9636 | CXXScopeSpec MapperIdScopeSpec; |
| 9637 | DeclarationNameInfo MapperIdInfo; |
| 9638 | llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 9639 | if (transformOMPMappableExprListClause<Derived, OMPMapClause>( |
| 9640 | *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 9641 | return nullptr; |
| 9642 | return getDerived().RebuildOMPMapClause( |
| 9643 | C->getMapTypeModifiers(), C->getMapTypeModifiersLoc(), MapperIdScopeSpec, |
| 9644 | MapperIdInfo, C->getMapType(), C->isImplicitMapType(), C->getMapLoc(), |
| 9645 | C->getColonLoc(), Vars, Locs, UnresolvedMappers); |
| 9646 | } |
| 9647 | |
| 9648 | template <typename Derived> |
| 9649 | OMPClause * |
| 9650 | TreeTransform<Derived>::TransformOMPAllocateClause(OMPAllocateClause *C) { |
| 9651 | Expr *Allocator = C->getAllocator(); |
| 9652 | if (Allocator) { |
| 9653 | ExprResult AllocatorRes = getDerived().TransformExpr(Allocator); |
| 9654 | if (AllocatorRes.isInvalid()) |
| 9655 | return nullptr; |
| 9656 | Allocator = AllocatorRes.get(); |
| 9657 | } |
| 9658 | llvm::SmallVector<Expr *, 16> Vars; |
| 9659 | Vars.reserve(C->varlist_size()); |
| 9660 | for (auto *VE : C->varlists()) { |
| 9661 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9662 | if (EVar.isInvalid()) |
| 9663 | return nullptr; |
| 9664 | Vars.push_back(EVar.get()); |
| 9665 | } |
| 9666 | return getDerived().RebuildOMPAllocateClause( |
| 9667 | Allocator, Vars, C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), |
| 9668 | C->getEndLoc()); |
| 9669 | } |
| 9670 | |
| 9671 | template <typename Derived> |
| 9672 | OMPClause * |
| 9673 | TreeTransform<Derived>::TransformOMPNumTeamsClause(OMPNumTeamsClause *C) { |
| 9674 | ExprResult E = getDerived().TransformExpr(C->getNumTeams()); |
| 9675 | if (E.isInvalid()) |
| 9676 | return nullptr; |
| 9677 | return getDerived().RebuildOMPNumTeamsClause( |
| 9678 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9679 | } |
| 9680 | |
| 9681 | template <typename Derived> |
| 9682 | OMPClause * |
| 9683 | TreeTransform<Derived>::TransformOMPThreadLimitClause(OMPThreadLimitClause *C) { |
| 9684 | ExprResult E = getDerived().TransformExpr(C->getThreadLimit()); |
| 9685 | if (E.isInvalid()) |
| 9686 | return nullptr; |
| 9687 | return getDerived().RebuildOMPThreadLimitClause( |
| 9688 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9689 | } |
| 9690 | |
| 9691 | template <typename Derived> |
| 9692 | OMPClause * |
| 9693 | TreeTransform<Derived>::TransformOMPPriorityClause(OMPPriorityClause *C) { |
| 9694 | ExprResult E = getDerived().TransformExpr(C->getPriority()); |
| 9695 | if (E.isInvalid()) |
| 9696 | return nullptr; |
| 9697 | return getDerived().RebuildOMPPriorityClause( |
| 9698 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9699 | } |
| 9700 | |
| 9701 | template <typename Derived> |
| 9702 | OMPClause * |
| 9703 | TreeTransform<Derived>::TransformOMPGrainsizeClause(OMPGrainsizeClause *C) { |
| 9704 | ExprResult E = getDerived().TransformExpr(C->getGrainsize()); |
| 9705 | if (E.isInvalid()) |
| 9706 | return nullptr; |
| 9707 | return getDerived().RebuildOMPGrainsizeClause( |
| 9708 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9709 | } |
| 9710 | |
| 9711 | template <typename Derived> |
| 9712 | OMPClause * |
| 9713 | TreeTransform<Derived>::TransformOMPNumTasksClause(OMPNumTasksClause *C) { |
| 9714 | ExprResult E = getDerived().TransformExpr(C->getNumTasks()); |
| 9715 | if (E.isInvalid()) |
| 9716 | return nullptr; |
| 9717 | return getDerived().RebuildOMPNumTasksClause( |
| 9718 | E.get(), C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9719 | } |
| 9720 | |
| 9721 | template <typename Derived> |
| 9722 | OMPClause *TreeTransform<Derived>::TransformOMPHintClause(OMPHintClause *C) { |
| 9723 | ExprResult E = getDerived().TransformExpr(C->getHint()); |
| 9724 | if (E.isInvalid()) |
| 9725 | return nullptr; |
| 9726 | return getDerived().RebuildOMPHintClause(E.get(), C->getBeginLoc(), |
| 9727 | C->getLParenLoc(), C->getEndLoc()); |
| 9728 | } |
| 9729 | |
| 9730 | template <typename Derived> |
| 9731 | OMPClause *TreeTransform<Derived>::TransformOMPDistScheduleClause( |
| 9732 | OMPDistScheduleClause *C) { |
| 9733 | ExprResult E = getDerived().TransformExpr(C->getChunkSize()); |
| 9734 | if (E.isInvalid()) |
| 9735 | return nullptr; |
| 9736 | return getDerived().RebuildOMPDistScheduleClause( |
| 9737 | C->getDistScheduleKind(), E.get(), C->getBeginLoc(), C->getLParenLoc(), |
| 9738 | C->getDistScheduleKindLoc(), C->getCommaLoc(), C->getEndLoc()); |
| 9739 | } |
| 9740 | |
| 9741 | template <typename Derived> |
| 9742 | OMPClause * |
| 9743 | TreeTransform<Derived>::TransformOMPDefaultmapClause(OMPDefaultmapClause *C) { |
| 9744 | // Rebuild Defaultmap Clause since we need to invoke the checking of |
| 9745 | // defaultmap(none:variable-category) after template initialization. |
| 9746 | return getDerived().RebuildOMPDefaultmapClause(C->getDefaultmapModifier(), |
| 9747 | C->getDefaultmapKind(), |
| 9748 | C->getBeginLoc(), |
| 9749 | C->getLParenLoc(), |
| 9750 | C->getDefaultmapModifierLoc(), |
| 9751 | C->getDefaultmapKindLoc(), |
| 9752 | C->getEndLoc()); |
| 9753 | } |
| 9754 | |
| 9755 | template <typename Derived> |
| 9756 | OMPClause *TreeTransform<Derived>::TransformOMPToClause(OMPToClause *C) { |
| 9757 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9758 | llvm::SmallVector<Expr *, 16> Vars; |
| 9759 | CXXScopeSpec MapperIdScopeSpec; |
| 9760 | DeclarationNameInfo MapperIdInfo; |
| 9761 | llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 9762 | if (transformOMPMappableExprListClause<Derived, OMPToClause>( |
| 9763 | *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 9764 | return nullptr; |
| 9765 | return getDerived().RebuildOMPToClause( |
| 9766 | C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec, |
| 9767 | MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers); |
| 9768 | } |
| 9769 | |
| 9770 | template <typename Derived> |
| 9771 | OMPClause *TreeTransform<Derived>::TransformOMPFromClause(OMPFromClause *C) { |
| 9772 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9773 | llvm::SmallVector<Expr *, 16> Vars; |
| 9774 | CXXScopeSpec MapperIdScopeSpec; |
| 9775 | DeclarationNameInfo MapperIdInfo; |
| 9776 | llvm::SmallVector<Expr *, 16> UnresolvedMappers; |
| 9777 | if (transformOMPMappableExprListClause<Derived, OMPFromClause>( |
| 9778 | *this, C, Vars, MapperIdScopeSpec, MapperIdInfo, UnresolvedMappers)) |
| 9779 | return nullptr; |
| 9780 | return getDerived().RebuildOMPFromClause( |
| 9781 | C->getMotionModifiers(), C->getMotionModifiersLoc(), MapperIdScopeSpec, |
| 9782 | MapperIdInfo, C->getColonLoc(), Vars, Locs, UnresolvedMappers); |
| 9783 | } |
| 9784 | |
| 9785 | template <typename Derived> |
| 9786 | OMPClause *TreeTransform<Derived>::TransformOMPUseDevicePtrClause( |
| 9787 | OMPUseDevicePtrClause *C) { |
| 9788 | llvm::SmallVector<Expr *, 16> Vars; |
| 9789 | Vars.reserve(C->varlist_size()); |
| 9790 | for (auto *VE : C->varlists()) { |
| 9791 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9792 | if (EVar.isInvalid()) |
| 9793 | return nullptr; |
| 9794 | Vars.push_back(EVar.get()); |
| 9795 | } |
| 9796 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9797 | return getDerived().RebuildOMPUseDevicePtrClause(Vars, Locs); |
| 9798 | } |
| 9799 | |
| 9800 | template <typename Derived> |
| 9801 | OMPClause *TreeTransform<Derived>::TransformOMPUseDeviceAddrClause( |
| 9802 | OMPUseDeviceAddrClause *C) { |
| 9803 | llvm::SmallVector<Expr *, 16> Vars; |
| 9804 | Vars.reserve(C->varlist_size()); |
| 9805 | for (auto *VE : C->varlists()) { |
| 9806 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9807 | if (EVar.isInvalid()) |
| 9808 | return nullptr; |
| 9809 | Vars.push_back(EVar.get()); |
| 9810 | } |
| 9811 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9812 | return getDerived().RebuildOMPUseDeviceAddrClause(Vars, Locs); |
| 9813 | } |
| 9814 | |
| 9815 | template <typename Derived> |
| 9816 | OMPClause * |
| 9817 | TreeTransform<Derived>::TransformOMPIsDevicePtrClause(OMPIsDevicePtrClause *C) { |
| 9818 | llvm::SmallVector<Expr *, 16> Vars; |
| 9819 | Vars.reserve(C->varlist_size()); |
| 9820 | for (auto *VE : C->varlists()) { |
| 9821 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9822 | if (EVar.isInvalid()) |
| 9823 | return nullptr; |
| 9824 | Vars.push_back(EVar.get()); |
| 9825 | } |
| 9826 | OMPVarListLocTy Locs(C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9827 | return getDerived().RebuildOMPIsDevicePtrClause(Vars, Locs); |
| 9828 | } |
| 9829 | |
| 9830 | template <typename Derived> |
| 9831 | OMPClause * |
| 9832 | TreeTransform<Derived>::TransformOMPNontemporalClause(OMPNontemporalClause *C) { |
| 9833 | llvm::SmallVector<Expr *, 16> Vars; |
| 9834 | Vars.reserve(C->varlist_size()); |
| 9835 | for (auto *VE : C->varlists()) { |
| 9836 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9837 | if (EVar.isInvalid()) |
| 9838 | return nullptr; |
| 9839 | Vars.push_back(EVar.get()); |
| 9840 | } |
| 9841 | return getDerived().RebuildOMPNontemporalClause( |
| 9842 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9843 | } |
| 9844 | |
| 9845 | template <typename Derived> |
| 9846 | OMPClause * |
| 9847 | TreeTransform<Derived>::TransformOMPInclusiveClause(OMPInclusiveClause *C) { |
| 9848 | llvm::SmallVector<Expr *, 16> Vars; |
| 9849 | Vars.reserve(C->varlist_size()); |
| 9850 | for (auto *VE : C->varlists()) { |
| 9851 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9852 | if (EVar.isInvalid()) |
| 9853 | return nullptr; |
| 9854 | Vars.push_back(EVar.get()); |
| 9855 | } |
| 9856 | return getDerived().RebuildOMPInclusiveClause( |
| 9857 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9858 | } |
| 9859 | |
| 9860 | template <typename Derived> |
| 9861 | OMPClause * |
| 9862 | TreeTransform<Derived>::TransformOMPExclusiveClause(OMPExclusiveClause *C) { |
| 9863 | llvm::SmallVector<Expr *, 16> Vars; |
| 9864 | Vars.reserve(C->varlist_size()); |
| 9865 | for (auto *VE : C->varlists()) { |
| 9866 | ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE)); |
| 9867 | if (EVar.isInvalid()) |
| 9868 | return nullptr; |
| 9869 | Vars.push_back(EVar.get()); |
| 9870 | } |
| 9871 | return getDerived().RebuildOMPExclusiveClause( |
| 9872 | Vars, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9873 | } |
| 9874 | |
| 9875 | template <typename Derived> |
| 9876 | OMPClause *TreeTransform<Derived>::TransformOMPUsesAllocatorsClause( |
| 9877 | OMPUsesAllocatorsClause *C) { |
| 9878 | SmallVector<Sema::UsesAllocatorsData, 16> Data; |
| 9879 | Data.reserve(C->getNumberOfAllocators()); |
| 9880 | for (unsigned I = 0, E = C->getNumberOfAllocators(); I < E; ++I) { |
| 9881 | OMPUsesAllocatorsClause::Data D = C->getAllocatorData(I); |
| 9882 | ExprResult Allocator = getDerived().TransformExpr(D.Allocator); |
| 9883 | if (Allocator.isInvalid()) |
| 9884 | continue; |
| 9885 | ExprResult AllocatorTraits; |
| 9886 | if (Expr *AT = D.AllocatorTraits) { |
| 9887 | AllocatorTraits = getDerived().TransformExpr(AT); |
| 9888 | if (AllocatorTraits.isInvalid()) |
| 9889 | continue; |
| 9890 | } |
| 9891 | Sema::UsesAllocatorsData &NewD = Data.emplace_back(); |
| 9892 | NewD.Allocator = Allocator.get(); |
| 9893 | NewD.AllocatorTraits = AllocatorTraits.get(); |
| 9894 | NewD.LParenLoc = D.LParenLoc; |
| 9895 | NewD.RParenLoc = D.RParenLoc; |
| 9896 | } |
| 9897 | return getDerived().RebuildOMPUsesAllocatorsClause( |
| 9898 | Data, C->getBeginLoc(), C->getLParenLoc(), C->getEndLoc()); |
| 9899 | } |
| 9900 | |
| 9901 | template <typename Derived> |
| 9902 | OMPClause * |
| 9903 | TreeTransform<Derived>::TransformOMPAffinityClause(OMPAffinityClause *C) { |
| 9904 | SmallVector<Expr *, 4> Locators; |
| 9905 | Locators.reserve(C->varlist_size()); |
| 9906 | ExprResult ModifierRes; |
| 9907 | if (Expr *Modifier = C->getModifier()) { |
| 9908 | ModifierRes = getDerived().TransformExpr(Modifier); |
| 9909 | if (ModifierRes.isInvalid()) |
| 9910 | return nullptr; |
| 9911 | } |
| 9912 | for (Expr *E : C->varlists()) { |
| 9913 | ExprResult Locator = getDerived().TransformExpr(E); |
| 9914 | if (Locator.isInvalid()) |
| 9915 | continue; |
| 9916 | Locators.push_back(Locator.get()); |
| 9917 | } |
| 9918 | return getDerived().RebuildOMPAffinityClause( |
| 9919 | C->getBeginLoc(), C->getLParenLoc(), C->getColonLoc(), C->getEndLoc(), |
| 9920 | ModifierRes.get(), Locators); |
| 9921 | } |
| 9922 | |
| 9923 | template <typename Derived> |
| 9924 | OMPClause *TreeTransform<Derived>::TransformOMPOrderClause(OMPOrderClause *C) { |
| 9925 | return getDerived().RebuildOMPOrderClause(C->getKind(), C->getKindKwLoc(), |
| 9926 | C->getBeginLoc(), C->getLParenLoc(), |
| 9927 | C->getEndLoc()); |
| 9928 | } |
| 9929 | |
| 9930 | //===----------------------------------------------------------------------===// |
| 9931 | // Expression transformation |
| 9932 | //===----------------------------------------------------------------------===// |
| 9933 | template<typename Derived> |
| 9934 | ExprResult |
| 9935 | TreeTransform<Derived>::TransformConstantExpr(ConstantExpr *E) { |
| 9936 | return TransformExpr(E->getSubExpr()); |
| 9937 | } |
| 9938 | |
| 9939 | template<typename Derived> |
| 9940 | ExprResult |
| 9941 | TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { |
| 9942 | if (!E->isTypeDependent()) |
| 9943 | return E; |
| 9944 | |
| 9945 | return getDerived().RebuildPredefinedExpr(E->getLocation(), |
| 9946 | E->getIdentKind()); |
| 9947 | } |
| 9948 | |
| 9949 | template<typename Derived> |
| 9950 | ExprResult |
| 9951 | TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { |
| 9952 | NestedNameSpecifierLoc QualifierLoc; |
| 9953 | if (E->getQualifierLoc()) { |
| 9954 | QualifierLoc |
| 9955 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 9956 | if (!QualifierLoc) |
| 9957 | return ExprError(); |
| 9958 | } |
| 9959 | |
| 9960 | ValueDecl *ND |
| 9961 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), |
| 9962 | E->getDecl())); |
| 9963 | if (!ND) |
| 9964 | return ExprError(); |
| 9965 | |
| 9966 | NamedDecl *Found = ND; |
| 9967 | if (E->getFoundDecl() != E->getDecl()) { |
| 9968 | Found = cast_or_null<NamedDecl>( |
| 9969 | getDerived().TransformDecl(E->getLocation(), E->getFoundDecl())); |
| 9970 | if (!Found) |
| 9971 | return ExprError(); |
| 9972 | } |
| 9973 | |
| 9974 | DeclarationNameInfo NameInfo = E->getNameInfo(); |
| 9975 | if (NameInfo.getName()) { |
| 9976 | NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); |
| 9977 | if (!NameInfo.getName()) |
| 9978 | return ExprError(); |
| 9979 | } |
| 9980 | |
| 9981 | if (!getDerived().AlwaysRebuild() && |
| 9982 | QualifierLoc == E->getQualifierLoc() && |
| 9983 | ND == E->getDecl() && |
| 9984 | Found == E->getFoundDecl() && |
| 9985 | NameInfo.getName() == E->getDecl()->getDeclName() && |
| 9986 | !E->hasExplicitTemplateArgs()) { |
| 9987 | |
| 9988 | // Mark it referenced in the new context regardless. |
| 9989 | // FIXME: this is a bit instantiation-specific. |
| 9990 | SemaRef.MarkDeclRefReferenced(E); |
| 9991 | |
| 9992 | return E; |
| 9993 | } |
| 9994 | |
| 9995 | TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr; |
| 9996 | if (E->hasExplicitTemplateArgs()) { |
| 9997 | TemplateArgs = &TransArgs; |
| 9998 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 9999 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 10000 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 10001 | E->getNumTemplateArgs(), |
| 10002 | TransArgs)) |
| 10003 | return ExprError(); |
| 10004 | } |
| 10005 | |
| 10006 | return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, |
| 10007 | Found, TemplateArgs); |
| 10008 | } |
| 10009 | |
| 10010 | template<typename Derived> |
| 10011 | ExprResult |
| 10012 | TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { |
| 10013 | return E; |
| 10014 | } |
| 10015 | |
| 10016 | template <typename Derived> |
| 10017 | ExprResult TreeTransform<Derived>::TransformFixedPointLiteral( |
| 10018 | FixedPointLiteral *E) { |
| 10019 | return E; |
| 10020 | } |
| 10021 | |
| 10022 | template<typename Derived> |
| 10023 | ExprResult |
| 10024 | TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { |
| 10025 | return E; |
| 10026 | } |
| 10027 | |
| 10028 | template<typename Derived> |
| 10029 | ExprResult |
| 10030 | TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { |
| 10031 | return E; |
| 10032 | } |
| 10033 | |
| 10034 | template<typename Derived> |
| 10035 | ExprResult |
| 10036 | TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { |
| 10037 | return E; |
| 10038 | } |
| 10039 | |
| 10040 | template<typename Derived> |
| 10041 | ExprResult |
| 10042 | TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { |
| 10043 | return E; |
| 10044 | } |
| 10045 | |
| 10046 | template<typename Derived> |
| 10047 | ExprResult |
| 10048 | TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { |
| 10049 | if (FunctionDecl *FD = E->getDirectCallee()) |
| 10050 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), FD); |
| 10051 | return SemaRef.MaybeBindToTemporary(E); |
| 10052 | } |
| 10053 | |
| 10054 | template<typename Derived> |
| 10055 | ExprResult |
| 10056 | TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { |
| 10057 | ExprResult ControllingExpr = |
| 10058 | getDerived().TransformExpr(E->getControllingExpr()); |
| 10059 | if (ControllingExpr.isInvalid()) |
| 10060 | return ExprError(); |
| 10061 | |
| 10062 | SmallVector<Expr *, 4> AssocExprs; |
| 10063 | SmallVector<TypeSourceInfo *, 4> AssocTypes; |
| 10064 | for (const GenericSelectionExpr::Association Assoc : E->associations()) { |
| 10065 | TypeSourceInfo *TSI = Assoc.getTypeSourceInfo(); |
| 10066 | if (TSI) { |
| 10067 | TypeSourceInfo *AssocType = getDerived().TransformType(TSI); |
| 10068 | if (!AssocType) |
| 10069 | return ExprError(); |
| 10070 | AssocTypes.push_back(AssocType); |
| 10071 | } else { |
| 10072 | AssocTypes.push_back(nullptr); |
| 10073 | } |
| 10074 | |
| 10075 | ExprResult AssocExpr = |
| 10076 | getDerived().TransformExpr(Assoc.getAssociationExpr()); |
| 10077 | if (AssocExpr.isInvalid()) |
| 10078 | return ExprError(); |
| 10079 | AssocExprs.push_back(AssocExpr.get()); |
| 10080 | } |
| 10081 | |
| 10082 | return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), |
| 10083 | E->getDefaultLoc(), |
| 10084 | E->getRParenLoc(), |
| 10085 | ControllingExpr.get(), |
| 10086 | AssocTypes, |
| 10087 | AssocExprs); |
| 10088 | } |
| 10089 | |
| 10090 | template<typename Derived> |
| 10091 | ExprResult |
| 10092 | TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { |
| 10093 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 10094 | if (SubExpr.isInvalid()) |
| 10095 | return ExprError(); |
| 10096 | |
| 10097 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
| 10098 | return E; |
| 10099 | |
| 10100 | return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), |
| 10101 | E->getRParen()); |
| 10102 | } |
| 10103 | |
| 10104 | /// The operand of a unary address-of operator has special rules: it's |
| 10105 | /// allowed to refer to a non-static member of a class even if there's no 'this' |
| 10106 | /// object available. |
| 10107 | template<typename Derived> |
| 10108 | ExprResult |
| 10109 | TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) { |
| 10110 | if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E)) |
| 10111 | return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr); |
| 10112 | else |
| 10113 | return getDerived().TransformExpr(E); |
| 10114 | } |
| 10115 | |
| 10116 | template<typename Derived> |
| 10117 | ExprResult |
| 10118 | TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { |
| 10119 | ExprResult SubExpr; |
| 10120 | if (E->getOpcode() == UO_AddrOf) |
| 10121 | SubExpr = TransformAddressOfOperand(E->getSubExpr()); |
| 10122 | else |
| 10123 | SubExpr = TransformExpr(E->getSubExpr()); |
| 10124 | if (SubExpr.isInvalid()) |
| 10125 | return ExprError(); |
| 10126 | |
| 10127 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) |
| 10128 | return E; |
| 10129 | |
| 10130 | return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), |
| 10131 | E->getOpcode(), |
| 10132 | SubExpr.get()); |
| 10133 | } |
| 10134 | |
| 10135 | template<typename Derived> |
| 10136 | ExprResult |
| 10137 | TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { |
| 10138 | // Transform the type. |
| 10139 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 10140 | if (!Type) |
| 10141 | return ExprError(); |
| 10142 | |
| 10143 | // Transform all of the components into components similar to what the |
| 10144 | // parser uses. |
| 10145 | // FIXME: It would be slightly more efficient in the non-dependent case to |
| 10146 | // just map FieldDecls, rather than requiring the rebuilder to look for |
| 10147 | // the fields again. However, __builtin_offsetof is rare enough in |
| 10148 | // template code that we don't care. |
| 10149 | bool ExprChanged = false; |
| 10150 | typedef Sema::OffsetOfComponent Component; |
| 10151 | SmallVector<Component, 4> Components; |
| 10152 | for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { |
| 10153 | const OffsetOfNode &ON = E->getComponent(I); |
| 10154 | Component Comp; |
| 10155 | Comp.isBrackets = true; |
| 10156 | Comp.LocStart = ON.getSourceRange().getBegin(); |
| 10157 | Comp.LocEnd = ON.getSourceRange().getEnd(); |
| 10158 | switch (ON.getKind()) { |
| 10159 | case OffsetOfNode::Array: { |
| 10160 | Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); |
| 10161 | ExprResult Index = getDerived().TransformExpr(FromIndex); |
| 10162 | if (Index.isInvalid()) |
| 10163 | return ExprError(); |
| 10164 | |
| 10165 | ExprChanged = ExprChanged || Index.get() != FromIndex; |
| 10166 | Comp.isBrackets = true; |
| 10167 | Comp.U.E = Index.get(); |
| 10168 | break; |
| 10169 | } |
| 10170 | |
| 10171 | case OffsetOfNode::Field: |
| 10172 | case OffsetOfNode::Identifier: |
| 10173 | Comp.isBrackets = false; |
| 10174 | Comp.U.IdentInfo = ON.getFieldName(); |
| 10175 | if (!Comp.U.IdentInfo) |
| 10176 | continue; |
| 10177 | |
| 10178 | break; |
| 10179 | |
| 10180 | case OffsetOfNode::Base: |
| 10181 | // Will be recomputed during the rebuild. |
| 10182 | continue; |
| 10183 | } |
| 10184 | |
| 10185 | Components.push_back(Comp); |
| 10186 | } |
| 10187 | |
| 10188 | // If nothing changed, retain the existing expression. |
| 10189 | if (!getDerived().AlwaysRebuild() && |
| 10190 | Type == E->getTypeSourceInfo() && |
| 10191 | !ExprChanged) |
| 10192 | return E; |
| 10193 | |
| 10194 | // Build a new offsetof expression. |
| 10195 | return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, |
| 10196 | Components, E->getRParenLoc()); |
| 10197 | } |
| 10198 | |
| 10199 | template<typename Derived> |
| 10200 | ExprResult |
| 10201 | TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { |
| 10202 | assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) && |
| 10203 | "opaque value expression requires transformation" ); |
| 10204 | return E; |
| 10205 | } |
| 10206 | |
| 10207 | template<typename Derived> |
| 10208 | ExprResult |
| 10209 | TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) { |
| 10210 | return E; |
| 10211 | } |
| 10212 | |
| 10213 | template <typename Derived> |
| 10214 | ExprResult TreeTransform<Derived>::TransformRecoveryExpr(RecoveryExpr *E) { |
| 10215 | llvm::SmallVector<Expr *, 8> Children; |
| 10216 | bool Changed = false; |
| 10217 | for (Expr *C : E->subExpressions()) { |
| 10218 | ExprResult NewC = getDerived().TransformExpr(C); |
| 10219 | if (NewC.isInvalid()) |
| 10220 | return ExprError(); |
| 10221 | Children.push_back(NewC.get()); |
| 10222 | |
| 10223 | Changed |= NewC.get() != C; |
| 10224 | } |
| 10225 | if (!getDerived().AlwaysRebuild() && !Changed) |
| 10226 | return E; |
| 10227 | return getDerived().RebuildRecoveryExpr(E->getBeginLoc(), E->getEndLoc(), |
| 10228 | Children, E->getType()); |
| 10229 | } |
| 10230 | |
| 10231 | template<typename Derived> |
| 10232 | ExprResult |
| 10233 | TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { |
| 10234 | // Rebuild the syntactic form. The original syntactic form has |
| 10235 | // opaque-value expressions in it, so strip those away and rebuild |
| 10236 | // the result. This is a really awful way of doing this, but the |
| 10237 | // better solution (rebuilding the semantic expressions and |
| 10238 | // rebinding OVEs as necessary) doesn't work; we'd need |
| 10239 | // TreeTransform to not strip away implicit conversions. |
| 10240 | Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); |
| 10241 | ExprResult result = getDerived().TransformExpr(newSyntacticForm); |
| 10242 | if (result.isInvalid()) return ExprError(); |
| 10243 | |
| 10244 | // If that gives us a pseudo-object result back, the pseudo-object |
| 10245 | // expression must have been an lvalue-to-rvalue conversion which we |
| 10246 | // should reapply. |
| 10247 | if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) |
| 10248 | result = SemaRef.checkPseudoObjectRValue(result.get()); |
| 10249 | |
| 10250 | return result; |
| 10251 | } |
| 10252 | |
| 10253 | template<typename Derived> |
| 10254 | ExprResult |
| 10255 | TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( |
| 10256 | UnaryExprOrTypeTraitExpr *E) { |
| 10257 | if (E->isArgumentType()) { |
| 10258 | TypeSourceInfo *OldT = E->getArgumentTypeInfo(); |
| 10259 | |
| 10260 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 10261 | if (!NewT) |
| 10262 | return ExprError(); |
| 10263 | |
| 10264 | if (!getDerived().AlwaysRebuild() && OldT == NewT) |
| 10265 | return E; |
| 10266 | |
| 10267 | return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), |
| 10268 | E->getKind(), |
| 10269 | E->getSourceRange()); |
| 10270 | } |
| 10271 | |
| 10272 | // C++0x [expr.sizeof]p1: |
| 10273 | // The operand is either an expression, which is an unevaluated operand |
| 10274 | // [...] |
| 10275 | EnterExpressionEvaluationContext Unevaluated( |
| 10276 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 10277 | Sema::ReuseLambdaContextDecl); |
| 10278 | |
| 10279 | // Try to recover if we have something like sizeof(T::X) where X is a type. |
| 10280 | // Notably, there must be *exactly* one set of parens if X is a type. |
| 10281 | TypeSourceInfo *RecoveryTSI = nullptr; |
| 10282 | ExprResult SubExpr; |
| 10283 | auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr()); |
| 10284 | if (auto *DRE = |
| 10285 | PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr) |
| 10286 | SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr( |
| 10287 | PE, DRE, false, &RecoveryTSI); |
| 10288 | else |
| 10289 | SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); |
| 10290 | |
| 10291 | if (RecoveryTSI) { |
| 10292 | return getDerived().RebuildUnaryExprOrTypeTrait( |
| 10293 | RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange()); |
| 10294 | } else if (SubExpr.isInvalid()) |
| 10295 | return ExprError(); |
| 10296 | |
| 10297 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) |
| 10298 | return E; |
| 10299 | |
| 10300 | return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), |
| 10301 | E->getOperatorLoc(), |
| 10302 | E->getKind(), |
| 10303 | E->getSourceRange()); |
| 10304 | } |
| 10305 | |
| 10306 | template<typename Derived> |
| 10307 | ExprResult |
| 10308 | TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { |
| 10309 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 10310 | if (LHS.isInvalid()) |
| 10311 | return ExprError(); |
| 10312 | |
| 10313 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 10314 | if (RHS.isInvalid()) |
| 10315 | return ExprError(); |
| 10316 | |
| 10317 | |
| 10318 | if (!getDerived().AlwaysRebuild() && |
| 10319 | LHS.get() == E->getLHS() && |
| 10320 | RHS.get() == E->getRHS()) |
| 10321 | return E; |
| 10322 | |
| 10323 | return getDerived().RebuildArraySubscriptExpr( |
| 10324 | LHS.get(), |
| 10325 | /*FIXME:*/ E->getLHS()->getBeginLoc(), RHS.get(), E->getRBracketLoc()); |
| 10326 | } |
| 10327 | |
| 10328 | template <typename Derived> |
| 10329 | ExprResult |
| 10330 | TreeTransform<Derived>::TransformMatrixSubscriptExpr(MatrixSubscriptExpr *E) { |
| 10331 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 10332 | if (Base.isInvalid()) |
| 10333 | return ExprError(); |
| 10334 | |
| 10335 | ExprResult RowIdx = getDerived().TransformExpr(E->getRowIdx()); |
| 10336 | if (RowIdx.isInvalid()) |
| 10337 | return ExprError(); |
| 10338 | |
| 10339 | ExprResult ColumnIdx = getDerived().TransformExpr(E->getColumnIdx()); |
| 10340 | if (ColumnIdx.isInvalid()) |
| 10341 | return ExprError(); |
| 10342 | |
| 10343 | if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && |
| 10344 | RowIdx.get() == E->getRowIdx() && ColumnIdx.get() == E->getColumnIdx()) |
| 10345 | return E; |
| 10346 | |
| 10347 | return getDerived().RebuildMatrixSubscriptExpr( |
| 10348 | Base.get(), RowIdx.get(), ColumnIdx.get(), E->getRBracketLoc()); |
| 10349 | } |
| 10350 | |
| 10351 | template <typename Derived> |
| 10352 | ExprResult |
| 10353 | TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) { |
| 10354 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 10355 | if (Base.isInvalid()) |
| 10356 | return ExprError(); |
| 10357 | |
| 10358 | ExprResult LowerBound; |
| 10359 | if (E->getLowerBound()) { |
| 10360 | LowerBound = getDerived().TransformExpr(E->getLowerBound()); |
| 10361 | if (LowerBound.isInvalid()) |
| 10362 | return ExprError(); |
| 10363 | } |
| 10364 | |
| 10365 | ExprResult Length; |
| 10366 | if (E->getLength()) { |
| 10367 | Length = getDerived().TransformExpr(E->getLength()); |
| 10368 | if (Length.isInvalid()) |
| 10369 | return ExprError(); |
| 10370 | } |
| 10371 | |
| 10372 | ExprResult Stride; |
| 10373 | if (Expr *Str = E->getStride()) { |
| 10374 | Stride = getDerived().TransformExpr(Str); |
| 10375 | if (Stride.isInvalid()) |
| 10376 | return ExprError(); |
| 10377 | } |
| 10378 | |
| 10379 | if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() && |
| 10380 | LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength()) |
| 10381 | return E; |
| 10382 | |
| 10383 | return getDerived().RebuildOMPArraySectionExpr( |
| 10384 | Base.get(), E->getBase()->getEndLoc(), LowerBound.get(), |
| 10385 | E->getColonLocFirst(), E->getColonLocSecond(), Length.get(), Stride.get(), |
| 10386 | E->getRBracketLoc()); |
| 10387 | } |
| 10388 | |
| 10389 | template <typename Derived> |
| 10390 | ExprResult |
| 10391 | TreeTransform<Derived>::TransformOMPArrayShapingExpr(OMPArrayShapingExpr *E) { |
| 10392 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 10393 | if (Base.isInvalid()) |
| 10394 | return ExprError(); |
| 10395 | |
| 10396 | SmallVector<Expr *, 4> Dims; |
| 10397 | bool ErrorFound = false; |
| 10398 | for (Expr *Dim : E->getDimensions()) { |
| 10399 | ExprResult DimRes = getDerived().TransformExpr(Dim); |
| 10400 | if (DimRes.isInvalid()) { |
| 10401 | ErrorFound = true; |
| 10402 | continue; |
| 10403 | } |
| 10404 | Dims.push_back(DimRes.get()); |
| 10405 | } |
| 10406 | |
| 10407 | if (ErrorFound) |
| 10408 | return ExprError(); |
| 10409 | return getDerived().RebuildOMPArrayShapingExpr(Base.get(), E->getLParenLoc(), |
| 10410 | E->getRParenLoc(), Dims, |
| 10411 | E->getBracketsRanges()); |
| 10412 | } |
| 10413 | |
| 10414 | template <typename Derived> |
| 10415 | ExprResult |
| 10416 | TreeTransform<Derived>::TransformOMPIteratorExpr(OMPIteratorExpr *E) { |
| 10417 | unsigned NumIterators = E->numOfIterators(); |
| 10418 | SmallVector<Sema::OMPIteratorData, 4> Data(NumIterators); |
| 10419 | |
| 10420 | bool ErrorFound = false; |
| 10421 | bool NeedToRebuild = getDerived().AlwaysRebuild(); |
| 10422 | for (unsigned I = 0; I < NumIterators; ++I) { |
| 10423 | auto *D = cast<VarDecl>(E->getIteratorDecl(I)); |
| 10424 | Data[I].DeclIdent = D->getIdentifier(); |
| 10425 | Data[I].DeclIdentLoc = D->getLocation(); |
| 10426 | if (D->getLocation() == D->getBeginLoc()) { |
| 10427 | assert(SemaRef.Context.hasSameType(D->getType(), SemaRef.Context.IntTy) && |
| 10428 | "Implicit type must be int." ); |
| 10429 | } else { |
| 10430 | TypeSourceInfo *TSI = getDerived().TransformType(D->getTypeSourceInfo()); |
| 10431 | QualType DeclTy = getDerived().TransformType(D->getType()); |
| 10432 | Data[I].Type = SemaRef.CreateParsedType(DeclTy, TSI); |
| 10433 | } |
| 10434 | OMPIteratorExpr::IteratorRange Range = E->getIteratorRange(I); |
| 10435 | ExprResult Begin = getDerived().TransformExpr(Range.Begin); |
| 10436 | ExprResult End = getDerived().TransformExpr(Range.End); |
| 10437 | ExprResult Step = getDerived().TransformExpr(Range.Step); |
| 10438 | ErrorFound = ErrorFound || |
| 10439 | !(!D->getTypeSourceInfo() || (Data[I].Type.getAsOpaquePtr() && |
| 10440 | !Data[I].Type.get().isNull())) || |
| 10441 | Begin.isInvalid() || End.isInvalid() || Step.isInvalid(); |
| 10442 | if (ErrorFound) |
| 10443 | continue; |
| 10444 | Data[I].Range.Begin = Begin.get(); |
| 10445 | Data[I].Range.End = End.get(); |
| 10446 | Data[I].Range.Step = Step.get(); |
| 10447 | Data[I].AssignLoc = E->getAssignLoc(I); |
| 10448 | Data[I].ColonLoc = E->getColonLoc(I); |
| 10449 | Data[I].SecColonLoc = E->getSecondColonLoc(I); |
| 10450 | NeedToRebuild = |
| 10451 | NeedToRebuild || |
| 10452 | (D->getTypeSourceInfo() && Data[I].Type.get().getTypePtrOrNull() != |
| 10453 | D->getType().getTypePtrOrNull()) || |
| 10454 | Range.Begin != Data[I].Range.Begin || Range.End != Data[I].Range.End || |
| 10455 | Range.Step != Data[I].Range.Step; |
| 10456 | } |
| 10457 | if (ErrorFound) |
| 10458 | return ExprError(); |
| 10459 | if (!NeedToRebuild) |
| 10460 | return E; |
| 10461 | |
| 10462 | ExprResult Res = getDerived().RebuildOMPIteratorExpr( |
| 10463 | E->getIteratorKwLoc(), E->getLParenLoc(), E->getRParenLoc(), Data); |
| 10464 | if (!Res.isUsable()) |
| 10465 | return Res; |
| 10466 | auto *IE = cast<OMPIteratorExpr>(Res.get()); |
| 10467 | for (unsigned I = 0; I < NumIterators; ++I) |
| 10468 | getDerived().transformedLocalDecl(E->getIteratorDecl(I), |
| 10469 | IE->getIteratorDecl(I)); |
| 10470 | return Res; |
| 10471 | } |
| 10472 | |
| 10473 | template<typename Derived> |
| 10474 | ExprResult |
| 10475 | TreeTransform<Derived>::TransformCallExpr(CallExpr *E) { |
| 10476 | // Transform the callee. |
| 10477 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 10478 | if (Callee.isInvalid()) |
| 10479 | return ExprError(); |
| 10480 | |
| 10481 | // Transform arguments. |
| 10482 | bool ArgChanged = false; |
| 10483 | SmallVector<Expr*, 8> Args; |
| 10484 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 10485 | &ArgChanged)) |
| 10486 | return ExprError(); |
| 10487 | |
| 10488 | if (!getDerived().AlwaysRebuild() && |
| 10489 | Callee.get() == E->getCallee() && |
| 10490 | !ArgChanged) |
| 10491 | return SemaRef.MaybeBindToTemporary(E); |
| 10492 | |
| 10493 | // FIXME: Wrong source location information for the '('. |
| 10494 | SourceLocation FakeLParenLoc |
| 10495 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 10496 | |
| 10497 | Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); |
| 10498 | if (E->hasStoredFPFeatures()) { |
| 10499 | FPOptionsOverride NewOverrides = E->getFPFeatures(); |
| 10500 | getSema().CurFPFeatures = |
| 10501 | NewOverrides.applyOverrides(getSema().getLangOpts()); |
| 10502 | getSema().FpPragmaStack.CurrentValue = NewOverrides; |
| 10503 | } |
| 10504 | |
| 10505 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 10506 | Args, |
| 10507 | E->getRParenLoc()); |
| 10508 | } |
| 10509 | |
| 10510 | template<typename Derived> |
| 10511 | ExprResult |
| 10512 | TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { |
| 10513 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 10514 | if (Base.isInvalid()) |
| 10515 | return ExprError(); |
| 10516 | |
| 10517 | NestedNameSpecifierLoc QualifierLoc; |
| 10518 | if (E->hasQualifier()) { |
| 10519 | QualifierLoc |
| 10520 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 10521 | |
| 10522 | if (!QualifierLoc) |
| 10523 | return ExprError(); |
| 10524 | } |
| 10525 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 10526 | |
| 10527 | ValueDecl *Member |
| 10528 | = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), |
| 10529 | E->getMemberDecl())); |
| 10530 | if (!Member) |
| 10531 | return ExprError(); |
| 10532 | |
| 10533 | NamedDecl *FoundDecl = E->getFoundDecl(); |
| 10534 | if (FoundDecl == E->getMemberDecl()) { |
| 10535 | FoundDecl = Member; |
| 10536 | } else { |
| 10537 | FoundDecl = cast_or_null<NamedDecl>( |
| 10538 | getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); |
| 10539 | if (!FoundDecl) |
| 10540 | return ExprError(); |
| 10541 | } |
| 10542 | |
| 10543 | if (!getDerived().AlwaysRebuild() && |
| 10544 | Base.get() == E->getBase() && |
| 10545 | QualifierLoc == E->getQualifierLoc() && |
| 10546 | Member == E->getMemberDecl() && |
| 10547 | FoundDecl == E->getFoundDecl() && |
| 10548 | !E->hasExplicitTemplateArgs()) { |
| 10549 | |
| 10550 | // Mark it referenced in the new context regardless. |
| 10551 | // FIXME: this is a bit instantiation-specific. |
| 10552 | SemaRef.MarkMemberReferenced(E); |
| 10553 | |
| 10554 | return E; |
| 10555 | } |
| 10556 | |
| 10557 | TemplateArgumentListInfo TransArgs; |
| 10558 | if (E->hasExplicitTemplateArgs()) { |
| 10559 | TransArgs.setLAngleLoc(E->getLAngleLoc()); |
| 10560 | TransArgs.setRAngleLoc(E->getRAngleLoc()); |
| 10561 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 10562 | E->getNumTemplateArgs(), |
| 10563 | TransArgs)) |
| 10564 | return ExprError(); |
| 10565 | } |
| 10566 | |
| 10567 | // FIXME: Bogus source location for the operator |
| 10568 | SourceLocation FakeOperatorLoc = |
| 10569 | SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); |
| 10570 | |
| 10571 | // FIXME: to do this check properly, we will need to preserve the |
| 10572 | // first-qualifier-in-scope here, just in case we had a dependent |
| 10573 | // base (and therefore couldn't do the check) and a |
| 10574 | // nested-name-qualifier (and therefore could do the lookup). |
| 10575 | NamedDecl *FirstQualifierInScope = nullptr; |
| 10576 | DeclarationNameInfo MemberNameInfo = E->getMemberNameInfo(); |
| 10577 | if (MemberNameInfo.getName()) { |
| 10578 | MemberNameInfo = getDerived().TransformDeclarationNameInfo(MemberNameInfo); |
| 10579 | if (!MemberNameInfo.getName()) |
| 10580 | return ExprError(); |
| 10581 | } |
| 10582 | |
| 10583 | return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, |
| 10584 | E->isArrow(), |
| 10585 | QualifierLoc, |
| 10586 | TemplateKWLoc, |
| 10587 | MemberNameInfo, |
| 10588 | Member, |
| 10589 | FoundDecl, |
| 10590 | (E->hasExplicitTemplateArgs() |
| 10591 | ? &TransArgs : nullptr), |
| 10592 | FirstQualifierInScope); |
| 10593 | } |
| 10594 | |
| 10595 | template<typename Derived> |
| 10596 | ExprResult |
| 10597 | TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { |
| 10598 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 10599 | if (LHS.isInvalid()) |
| 10600 | return ExprError(); |
| 10601 | |
| 10602 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 10603 | if (RHS.isInvalid()) |
| 10604 | return ExprError(); |
| 10605 | |
| 10606 | if (!getDerived().AlwaysRebuild() && |
| 10607 | LHS.get() == E->getLHS() && |
| 10608 | RHS.get() == E->getRHS()) |
| 10609 | return E; |
| 10610 | |
| 10611 | if (E->isCompoundAssignmentOp()) |
| 10612 | // FPFeatures has already been established from trailing storage |
| 10613 | return getDerived().RebuildBinaryOperator( |
| 10614 | E->getOperatorLoc(), E->getOpcode(), LHS.get(), RHS.get()); |
| 10615 | Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); |
| 10616 | FPOptionsOverride NewOverrides(E->getFPFeatures(getSema().getLangOpts())); |
| 10617 | getSema().CurFPFeatures = |
| 10618 | NewOverrides.applyOverrides(getSema().getLangOpts()); |
| 10619 | getSema().FpPragmaStack.CurrentValue = NewOverrides; |
| 10620 | return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), |
| 10621 | LHS.get(), RHS.get()); |
| 10622 | } |
| 10623 | |
| 10624 | template <typename Derived> |
| 10625 | ExprResult TreeTransform<Derived>::TransformCXXRewrittenBinaryOperator( |
| 10626 | CXXRewrittenBinaryOperator *E) { |
| 10627 | CXXRewrittenBinaryOperator::DecomposedForm Decomp = E->getDecomposedForm(); |
| 10628 | |
| 10629 | ExprResult LHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.LHS)); |
| 10630 | if (LHS.isInvalid()) |
| 10631 | return ExprError(); |
| 10632 | |
| 10633 | ExprResult RHS = getDerived().TransformExpr(const_cast<Expr*>(Decomp.RHS)); |
| 10634 | if (RHS.isInvalid()) |
| 10635 | return ExprError(); |
| 10636 | |
| 10637 | if (!getDerived().AlwaysRebuild() && |
| 10638 | LHS.get() == Decomp.LHS && |
| 10639 | RHS.get() == Decomp.RHS) |
| 10640 | return E; |
| 10641 | |
| 10642 | // Extract the already-resolved callee declarations so that we can restrict |
| 10643 | // ourselves to using them as the unqualified lookup results when rebuilding. |
| 10644 | UnresolvedSet<2> UnqualLookups; |
| 10645 | Expr *PossibleBinOps[] = {E->getSemanticForm(), |
| 10646 | const_cast<Expr *>(Decomp.InnerBinOp)}; |
| 10647 | for (Expr *PossibleBinOp : PossibleBinOps) { |
| 10648 | auto *Op = dyn_cast<CXXOperatorCallExpr>(PossibleBinOp->IgnoreImplicit()); |
| 10649 | if (!Op) |
| 10650 | continue; |
| 10651 | auto *Callee = dyn_cast<DeclRefExpr>(Op->getCallee()->IgnoreImplicit()); |
| 10652 | if (!Callee || isa<CXXMethodDecl>(Callee->getDecl())) |
| 10653 | continue; |
| 10654 | |
| 10655 | // Transform the callee in case we built a call to a local extern |
| 10656 | // declaration. |
| 10657 | NamedDecl *Found = cast_or_null<NamedDecl>(getDerived().TransformDecl( |
| 10658 | E->getOperatorLoc(), Callee->getFoundDecl())); |
| 10659 | if (!Found) |
| 10660 | return ExprError(); |
| 10661 | UnqualLookups.addDecl(Found); |
| 10662 | } |
| 10663 | |
| 10664 | return getDerived().RebuildCXXRewrittenBinaryOperator( |
| 10665 | E->getOperatorLoc(), Decomp.Opcode, UnqualLookups, LHS.get(), RHS.get()); |
| 10666 | } |
| 10667 | |
| 10668 | template<typename Derived> |
| 10669 | ExprResult |
| 10670 | TreeTransform<Derived>::TransformCompoundAssignOperator( |
| 10671 | CompoundAssignOperator *E) { |
| 10672 | Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); |
| 10673 | FPOptionsOverride NewOverrides(E->getFPFeatures(getSema().getLangOpts())); |
| 10674 | getSema().CurFPFeatures = |
| 10675 | NewOverrides.applyOverrides(getSema().getLangOpts()); |
| 10676 | getSema().FpPragmaStack.CurrentValue = NewOverrides; |
| 10677 | return getDerived().TransformBinaryOperator(E); |
| 10678 | } |
| 10679 | |
| 10680 | template<typename Derived> |
| 10681 | ExprResult TreeTransform<Derived>:: |
| 10682 | TransformBinaryConditionalOperator(BinaryConditionalOperator *e) { |
| 10683 | // Just rebuild the common and RHS expressions and see whether we |
| 10684 | // get any changes. |
| 10685 | |
| 10686 | ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); |
| 10687 | if (commonExpr.isInvalid()) |
| 10688 | return ExprError(); |
| 10689 | |
| 10690 | ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); |
| 10691 | if (rhs.isInvalid()) |
| 10692 | return ExprError(); |
| 10693 | |
| 10694 | if (!getDerived().AlwaysRebuild() && |
| 10695 | commonExpr.get() == e->getCommon() && |
| 10696 | rhs.get() == e->getFalseExpr()) |
| 10697 | return e; |
| 10698 | |
| 10699 | return getDerived().RebuildConditionalOperator(commonExpr.get(), |
| 10700 | e->getQuestionLoc(), |
| 10701 | nullptr, |
| 10702 | e->getColonLoc(), |
| 10703 | rhs.get()); |
| 10704 | } |
| 10705 | |
| 10706 | template<typename Derived> |
| 10707 | ExprResult |
| 10708 | TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { |
| 10709 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 10710 | if (Cond.isInvalid()) |
| 10711 | return ExprError(); |
| 10712 | |
| 10713 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 10714 | if (LHS.isInvalid()) |
| 10715 | return ExprError(); |
| 10716 | |
| 10717 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 10718 | if (RHS.isInvalid()) |
| 10719 | return ExprError(); |
| 10720 | |
| 10721 | if (!getDerived().AlwaysRebuild() && |
| 10722 | Cond.get() == E->getCond() && |
| 10723 | LHS.get() == E->getLHS() && |
| 10724 | RHS.get() == E->getRHS()) |
| 10725 | return E; |
| 10726 | |
| 10727 | return getDerived().RebuildConditionalOperator(Cond.get(), |
| 10728 | E->getQuestionLoc(), |
| 10729 | LHS.get(), |
| 10730 | E->getColonLoc(), |
| 10731 | RHS.get()); |
| 10732 | } |
| 10733 | |
| 10734 | template<typename Derived> |
| 10735 | ExprResult |
| 10736 | TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { |
| 10737 | // Implicit casts are eliminated during transformation, since they |
| 10738 | // will be recomputed by semantic analysis after transformation. |
| 10739 | return getDerived().TransformExpr(E->getSubExprAsWritten()); |
| 10740 | } |
| 10741 | |
| 10742 | template<typename Derived> |
| 10743 | ExprResult |
| 10744 | TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { |
| 10745 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 10746 | if (!Type) |
| 10747 | return ExprError(); |
| 10748 | |
| 10749 | ExprResult SubExpr |
| 10750 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| 10751 | if (SubExpr.isInvalid()) |
| 10752 | return ExprError(); |
| 10753 | |
| 10754 | if (!getDerived().AlwaysRebuild() && |
| 10755 | Type == E->getTypeInfoAsWritten() && |
| 10756 | SubExpr.get() == E->getSubExpr()) |
| 10757 | return E; |
| 10758 | |
| 10759 | return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), |
| 10760 | Type, |
| 10761 | E->getRParenLoc(), |
| 10762 | SubExpr.get()); |
| 10763 | } |
| 10764 | |
| 10765 | template<typename Derived> |
| 10766 | ExprResult |
| 10767 | TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { |
| 10768 | TypeSourceInfo *OldT = E->getTypeSourceInfo(); |
| 10769 | TypeSourceInfo *NewT = getDerived().TransformType(OldT); |
| 10770 | if (!NewT) |
| 10771 | return ExprError(); |
| 10772 | |
| 10773 | ExprResult Init = getDerived().TransformExpr(E->getInitializer()); |
| 10774 | if (Init.isInvalid()) |
| 10775 | return ExprError(); |
| 10776 | |
| 10777 | if (!getDerived().AlwaysRebuild() && |
| 10778 | OldT == NewT && |
| 10779 | Init.get() == E->getInitializer()) |
| 10780 | return SemaRef.MaybeBindToTemporary(E); |
| 10781 | |
| 10782 | // Note: the expression type doesn't necessarily match the |
| 10783 | // type-as-written, but that's okay, because it should always be |
| 10784 | // derivable from the initializer. |
| 10785 | |
| 10786 | return getDerived().RebuildCompoundLiteralExpr( |
| 10787 | E->getLParenLoc(), NewT, |
| 10788 | /*FIXME:*/ E->getInitializer()->getEndLoc(), Init.get()); |
| 10789 | } |
| 10790 | |
| 10791 | template<typename Derived> |
| 10792 | ExprResult |
| 10793 | TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { |
| 10794 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 10795 | if (Base.isInvalid()) |
| 10796 | return ExprError(); |
| 10797 | |
| 10798 | if (!getDerived().AlwaysRebuild() && |
| 10799 | Base.get() == E->getBase()) |
| 10800 | return E; |
| 10801 | |
| 10802 | // FIXME: Bad source location |
| 10803 | SourceLocation FakeOperatorLoc = |
| 10804 | SemaRef.getLocForEndOfToken(E->getBase()->getEndLoc()); |
| 10805 | return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, |
| 10806 | E->getAccessorLoc(), |
| 10807 | E->getAccessor()); |
| 10808 | } |
| 10809 | |
| 10810 | template<typename Derived> |
| 10811 | ExprResult |
| 10812 | TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { |
| 10813 | if (InitListExpr *Syntactic = E->getSyntacticForm()) |
| 10814 | E = Syntactic; |
| 10815 | |
| 10816 | bool InitChanged = false; |
| 10817 | |
| 10818 | EnterExpressionEvaluationContext Context( |
| 10819 | getSema(), EnterExpressionEvaluationContext::InitList); |
| 10820 | |
| 10821 | SmallVector<Expr*, 4> Inits; |
| 10822 | if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, |
| 10823 | Inits, &InitChanged)) |
| 10824 | return ExprError(); |
| 10825 | |
| 10826 | if (!getDerived().AlwaysRebuild() && !InitChanged) { |
| 10827 | // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr |
| 10828 | // in some cases. We can't reuse it in general, because the syntactic and |
| 10829 | // semantic forms are linked, and we can't know that semantic form will |
| 10830 | // match even if the syntactic form does. |
| 10831 | } |
| 10832 | |
| 10833 | return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, |
| 10834 | E->getRBraceLoc()); |
| 10835 | } |
| 10836 | |
| 10837 | template<typename Derived> |
| 10838 | ExprResult |
| 10839 | TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { |
| 10840 | Designation Desig; |
| 10841 | |
| 10842 | // transform the initializer value |
| 10843 | ExprResult Init = getDerived().TransformExpr(E->getInit()); |
| 10844 | if (Init.isInvalid()) |
| 10845 | return ExprError(); |
| 10846 | |
| 10847 | // transform the designators. |
| 10848 | SmallVector<Expr*, 4> ArrayExprs; |
| 10849 | bool ExprChanged = false; |
| 10850 | for (const DesignatedInitExpr::Designator &D : E->designators()) { |
| 10851 | if (D.isFieldDesignator()) { |
| 10852 | Desig.AddDesignator(Designator::getField(D.getFieldName(), |
| 10853 | D.getDotLoc(), |
| 10854 | D.getFieldLoc())); |
| 10855 | if (D.getField()) { |
| 10856 | FieldDecl *Field = cast_or_null<FieldDecl>( |
| 10857 | getDerived().TransformDecl(D.getFieldLoc(), D.getField())); |
| 10858 | if (Field != D.getField()) |
| 10859 | // Rebuild the expression when the transformed FieldDecl is |
| 10860 | // different to the already assigned FieldDecl. |
| 10861 | ExprChanged = true; |
| 10862 | } else { |
| 10863 | // Ensure that the designator expression is rebuilt when there isn't |
| 10864 | // a resolved FieldDecl in the designator as we don't want to assign |
| 10865 | // a FieldDecl to a pattern designator that will be instantiated again. |
| 10866 | ExprChanged = true; |
| 10867 | } |
| 10868 | continue; |
| 10869 | } |
| 10870 | |
| 10871 | if (D.isArrayDesignator()) { |
| 10872 | ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(D)); |
| 10873 | if (Index.isInvalid()) |
| 10874 | return ExprError(); |
| 10875 | |
| 10876 | Desig.AddDesignator( |
| 10877 | Designator::getArray(Index.get(), D.getLBracketLoc())); |
| 10878 | |
| 10879 | ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(D); |
| 10880 | ArrayExprs.push_back(Index.get()); |
| 10881 | continue; |
| 10882 | } |
| 10883 | |
| 10884 | assert(D.isArrayRangeDesignator() && "New kind of designator?" ); |
| 10885 | ExprResult Start |
| 10886 | = getDerived().TransformExpr(E->getArrayRangeStart(D)); |
| 10887 | if (Start.isInvalid()) |
| 10888 | return ExprError(); |
| 10889 | |
| 10890 | ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(D)); |
| 10891 | if (End.isInvalid()) |
| 10892 | return ExprError(); |
| 10893 | |
| 10894 | Desig.AddDesignator(Designator::getArrayRange(Start.get(), |
| 10895 | End.get(), |
| 10896 | D.getLBracketLoc(), |
| 10897 | D.getEllipsisLoc())); |
| 10898 | |
| 10899 | ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(D) || |
| 10900 | End.get() != E->getArrayRangeEnd(D); |
| 10901 | |
| 10902 | ArrayExprs.push_back(Start.get()); |
| 10903 | ArrayExprs.push_back(End.get()); |
| 10904 | } |
| 10905 | |
| 10906 | if (!getDerived().AlwaysRebuild() && |
| 10907 | Init.get() == E->getInit() && |
| 10908 | !ExprChanged) |
| 10909 | return E; |
| 10910 | |
| 10911 | return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, |
| 10912 | E->getEqualOrColonLoc(), |
| 10913 | E->usesGNUSyntax(), Init.get()); |
| 10914 | } |
| 10915 | |
| 10916 | // Seems that if TransformInitListExpr() only works on the syntactic form of an |
| 10917 | // InitListExpr, then a DesignatedInitUpdateExpr is not encountered. |
| 10918 | template<typename Derived> |
| 10919 | ExprResult |
| 10920 | TreeTransform<Derived>::TransformDesignatedInitUpdateExpr( |
| 10921 | DesignatedInitUpdateExpr *E) { |
| 10922 | llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of " |
| 10923 | "initializer" ); |
| 10924 | return ExprError(); |
| 10925 | } |
| 10926 | |
| 10927 | template<typename Derived> |
| 10928 | ExprResult |
| 10929 | TreeTransform<Derived>::TransformNoInitExpr( |
| 10930 | NoInitExpr *E) { |
| 10931 | llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer" ); |
| 10932 | return ExprError(); |
| 10933 | } |
| 10934 | |
| 10935 | template<typename Derived> |
| 10936 | ExprResult |
| 10937 | TreeTransform<Derived>::TransformArrayInitLoopExpr(ArrayInitLoopExpr *E) { |
| 10938 | llvm_unreachable("Unexpected ArrayInitLoopExpr outside of initializer" ); |
| 10939 | return ExprError(); |
| 10940 | } |
| 10941 | |
| 10942 | template<typename Derived> |
| 10943 | ExprResult |
| 10944 | TreeTransform<Derived>::TransformArrayInitIndexExpr(ArrayInitIndexExpr *E) { |
| 10945 | llvm_unreachable("Unexpected ArrayInitIndexExpr outside of initializer" ); |
| 10946 | return ExprError(); |
| 10947 | } |
| 10948 | |
| 10949 | template<typename Derived> |
| 10950 | ExprResult |
| 10951 | TreeTransform<Derived>::TransformImplicitValueInitExpr( |
| 10952 | ImplicitValueInitExpr *E) { |
| 10953 | TemporaryBase Rebase(*this, E->getBeginLoc(), DeclarationName()); |
| 10954 | |
| 10955 | // FIXME: Will we ever have proper type location here? Will we actually |
| 10956 | // need to transform the type? |
| 10957 | QualType T = getDerived().TransformType(E->getType()); |
| 10958 | if (T.isNull()) |
| 10959 | return ExprError(); |
| 10960 | |
| 10961 | if (!getDerived().AlwaysRebuild() && |
| 10962 | T == E->getType()) |
| 10963 | return E; |
| 10964 | |
| 10965 | return getDerived().RebuildImplicitValueInitExpr(T); |
| 10966 | } |
| 10967 | |
| 10968 | template<typename Derived> |
| 10969 | ExprResult |
| 10970 | TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { |
| 10971 | TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); |
| 10972 | if (!TInfo) |
| 10973 | return ExprError(); |
| 10974 | |
| 10975 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 10976 | if (SubExpr.isInvalid()) |
| 10977 | return ExprError(); |
| 10978 | |
| 10979 | if (!getDerived().AlwaysRebuild() && |
| 10980 | TInfo == E->getWrittenTypeInfo() && |
| 10981 | SubExpr.get() == E->getSubExpr()) |
| 10982 | return E; |
| 10983 | |
| 10984 | return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), |
| 10985 | TInfo, E->getRParenLoc()); |
| 10986 | } |
| 10987 | |
| 10988 | template<typename Derived> |
| 10989 | ExprResult |
| 10990 | TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { |
| 10991 | bool ArgumentChanged = false; |
| 10992 | SmallVector<Expr*, 4> Inits; |
| 10993 | if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, |
| 10994 | &ArgumentChanged)) |
| 10995 | return ExprError(); |
| 10996 | |
| 10997 | return getDerived().RebuildParenListExpr(E->getLParenLoc(), |
| 10998 | Inits, |
| 10999 | E->getRParenLoc()); |
| 11000 | } |
| 11001 | |
| 11002 | /// Transform an address-of-label expression. |
| 11003 | /// |
| 11004 | /// By default, the transformation of an address-of-label expression always |
| 11005 | /// rebuilds the expression, so that the label identifier can be resolved to |
| 11006 | /// the corresponding label statement by semantic analysis. |
| 11007 | template<typename Derived> |
| 11008 | ExprResult |
| 11009 | TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { |
| 11010 | Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), |
| 11011 | E->getLabel()); |
| 11012 | if (!LD) |
| 11013 | return ExprError(); |
| 11014 | |
| 11015 | return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), |
| 11016 | cast<LabelDecl>(LD)); |
| 11017 | } |
| 11018 | |
| 11019 | template<typename Derived> |
| 11020 | ExprResult |
| 11021 | TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { |
| 11022 | SemaRef.ActOnStartStmtExpr(); |
| 11023 | StmtResult SubStmt |
| 11024 | = getDerived().TransformCompoundStmt(E->getSubStmt(), true); |
| 11025 | if (SubStmt.isInvalid()) { |
| 11026 | SemaRef.ActOnStmtExprError(); |
| 11027 | return ExprError(); |
| 11028 | } |
| 11029 | |
| 11030 | unsigned OldDepth = E->getTemplateDepth(); |
| 11031 | unsigned NewDepth = getDerived().TransformTemplateDepth(OldDepth); |
| 11032 | |
| 11033 | if (!getDerived().AlwaysRebuild() && OldDepth == NewDepth && |
| 11034 | SubStmt.get() == E->getSubStmt()) { |
| 11035 | // Calling this an 'error' is unintuitive, but it does the right thing. |
| 11036 | SemaRef.ActOnStmtExprError(); |
| 11037 | return SemaRef.MaybeBindToTemporary(E); |
| 11038 | } |
| 11039 | |
| 11040 | return getDerived().RebuildStmtExpr(E->getLParenLoc(), SubStmt.get(), |
| 11041 | E->getRParenLoc(), NewDepth); |
| 11042 | } |
| 11043 | |
| 11044 | template<typename Derived> |
| 11045 | ExprResult |
| 11046 | TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { |
| 11047 | ExprResult Cond = getDerived().TransformExpr(E->getCond()); |
| 11048 | if (Cond.isInvalid()) |
| 11049 | return ExprError(); |
| 11050 | |
| 11051 | ExprResult LHS = getDerived().TransformExpr(E->getLHS()); |
| 11052 | if (LHS.isInvalid()) |
| 11053 | return ExprError(); |
| 11054 | |
| 11055 | ExprResult RHS = getDerived().TransformExpr(E->getRHS()); |
| 11056 | if (RHS.isInvalid()) |
| 11057 | return ExprError(); |
| 11058 | |
| 11059 | if (!getDerived().AlwaysRebuild() && |
| 11060 | Cond.get() == E->getCond() && |
| 11061 | LHS.get() == E->getLHS() && |
| 11062 | RHS.get() == E->getRHS()) |
| 11063 | return E; |
| 11064 | |
| 11065 | return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), |
| 11066 | Cond.get(), LHS.get(), RHS.get(), |
| 11067 | E->getRParenLoc()); |
| 11068 | } |
| 11069 | |
| 11070 | template<typename Derived> |
| 11071 | ExprResult |
| 11072 | TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { |
| 11073 | return E; |
| 11074 | } |
| 11075 | |
| 11076 | template<typename Derived> |
| 11077 | ExprResult |
| 11078 | TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { |
| 11079 | switch (E->getOperator()) { |
| 11080 | case OO_New: |
| 11081 | case OO_Delete: |
| 11082 | case OO_Array_New: |
| 11083 | case OO_Array_Delete: |
| 11084 | llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr" ); |
| 11085 | |
| 11086 | case OO_Call: { |
| 11087 | // This is a call to an object's operator(). |
| 11088 | assert(E->getNumArgs() >= 1 && "Object call is missing arguments" ); |
| 11089 | |
| 11090 | // Transform the object itself. |
| 11091 | ExprResult Object = getDerived().TransformExpr(E->getArg(0)); |
| 11092 | if (Object.isInvalid()) |
| 11093 | return ExprError(); |
| 11094 | |
| 11095 | // FIXME: Poor location information |
| 11096 | SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken( |
| 11097 | static_cast<Expr *>(Object.get())->getEndLoc()); |
| 11098 | |
| 11099 | // Transform the call arguments. |
| 11100 | SmallVector<Expr*, 8> Args; |
| 11101 | if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, |
| 11102 | Args)) |
| 11103 | return ExprError(); |
| 11104 | |
| 11105 | return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, Args, |
| 11106 | E->getEndLoc()); |
| 11107 | } |
| 11108 | |
| 11109 | #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ |
| 11110 | case OO_##Name: |
| 11111 | #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) |
| 11112 | #include "clang/Basic/OperatorKinds.def" |
| 11113 | case OO_Subscript: |
| 11114 | // Handled below. |
| 11115 | break; |
| 11116 | |
| 11117 | case OO_Conditional: |
| 11118 | llvm_unreachable("conditional operator is not actually overloadable" ); |
| 11119 | |
| 11120 | case OO_None: |
| 11121 | case NUM_OVERLOADED_OPERATORS: |
| 11122 | llvm_unreachable("not an overloaded operator?" ); |
| 11123 | } |
| 11124 | |
| 11125 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 11126 | if (Callee.isInvalid()) |
| 11127 | return ExprError(); |
| 11128 | |
| 11129 | ExprResult First; |
| 11130 | if (E->getOperator() == OO_Amp) |
| 11131 | First = getDerived().TransformAddressOfOperand(E->getArg(0)); |
| 11132 | else |
| 11133 | First = getDerived().TransformExpr(E->getArg(0)); |
| 11134 | if (First.isInvalid()) |
| 11135 | return ExprError(); |
| 11136 | |
| 11137 | ExprResult Second; |
| 11138 | if (E->getNumArgs() == 2) { |
| 11139 | Second = getDerived().TransformExpr(E->getArg(1)); |
| 11140 | if (Second.isInvalid()) |
| 11141 | return ExprError(); |
| 11142 | } |
| 11143 | |
| 11144 | if (!getDerived().AlwaysRebuild() && |
| 11145 | Callee.get() == E->getCallee() && |
| 11146 | First.get() == E->getArg(0) && |
| 11147 | (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) |
| 11148 | return SemaRef.MaybeBindToTemporary(E); |
| 11149 | |
| 11150 | Sema::FPFeaturesStateRAII FPFeaturesState(getSema()); |
| 11151 | FPOptionsOverride NewOverrides(E->getFPFeatures()); |
| 11152 | getSema().CurFPFeatures = |
| 11153 | NewOverrides.applyOverrides(getSema().getLangOpts()); |
| 11154 | getSema().FpPragmaStack.CurrentValue = NewOverrides; |
| 11155 | |
| 11156 | return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), |
| 11157 | E->getOperatorLoc(), |
| 11158 | Callee.get(), |
| 11159 | First.get(), |
| 11160 | Second.get()); |
| 11161 | } |
| 11162 | |
| 11163 | template<typename Derived> |
| 11164 | ExprResult |
| 11165 | TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { |
| 11166 | return getDerived().TransformCallExpr(E); |
| 11167 | } |
| 11168 | |
| 11169 | template <typename Derived> |
| 11170 | ExprResult TreeTransform<Derived>::TransformSourceLocExpr(SourceLocExpr *E) { |
| 11171 | bool NeedRebuildFunc = E->getIdentKind() == SourceLocExpr::Function && |
| 11172 | getSema().CurContext != E->getParentContext(); |
| 11173 | |
| 11174 | if (!getDerived().AlwaysRebuild() && !NeedRebuildFunc) |
| 11175 | return E; |
| 11176 | |
| 11177 | return getDerived().RebuildSourceLocExpr(E->getIdentKind(), E->getBeginLoc(), |
| 11178 | E->getEndLoc(), |
| 11179 | getSema().CurContext); |
| 11180 | } |
| 11181 | |
| 11182 | template<typename Derived> |
| 11183 | ExprResult |
| 11184 | TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { |
| 11185 | // Transform the callee. |
| 11186 | ExprResult Callee = getDerived().TransformExpr(E->getCallee()); |
| 11187 | if (Callee.isInvalid()) |
| 11188 | return ExprError(); |
| 11189 | |
| 11190 | // Transform exec config. |
| 11191 | ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); |
| 11192 | if (EC.isInvalid()) |
| 11193 | return ExprError(); |
| 11194 | |
| 11195 | // Transform arguments. |
| 11196 | bool ArgChanged = false; |
| 11197 | SmallVector<Expr*, 8> Args; |
| 11198 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 11199 | &ArgChanged)) |
| 11200 | return ExprError(); |
| 11201 | |
| 11202 | if (!getDerived().AlwaysRebuild() && |
| 11203 | Callee.get() == E->getCallee() && |
| 11204 | !ArgChanged) |
| 11205 | return SemaRef.MaybeBindToTemporary(E); |
| 11206 | |
| 11207 | // FIXME: Wrong source location information for the '('. |
| 11208 | SourceLocation FakeLParenLoc |
| 11209 | = ((Expr *)Callee.get())->getSourceRange().getBegin(); |
| 11210 | return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, |
| 11211 | Args, |
| 11212 | E->getRParenLoc(), EC.get()); |
| 11213 | } |
| 11214 | |
| 11215 | template<typename Derived> |
| 11216 | ExprResult |
| 11217 | TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { |
| 11218 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 11219 | if (!Type) |
| 11220 | return ExprError(); |
| 11221 | |
| 11222 | ExprResult SubExpr |
| 11223 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| 11224 | if (SubExpr.isInvalid()) |
| 11225 | return ExprError(); |
| 11226 | |
| 11227 | if (!getDerived().AlwaysRebuild() && |
| 11228 | Type == E->getTypeInfoAsWritten() && |
| 11229 | SubExpr.get() == E->getSubExpr()) |
| 11230 | return E; |
| 11231 | return getDerived().RebuildCXXNamedCastExpr( |
| 11232 | E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(), |
| 11233 | Type, E->getAngleBrackets().getEnd(), |
| 11234 | // FIXME. this should be '(' location |
| 11235 | E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc()); |
| 11236 | } |
| 11237 | |
| 11238 | template<typename Derived> |
| 11239 | ExprResult |
| 11240 | TreeTransform<Derived>::TransformBuiltinBitCastExpr(BuiltinBitCastExpr *BCE) { |
| 11241 | TypeSourceInfo *TSI = |
| 11242 | getDerived().TransformType(BCE->getTypeInfoAsWritten()); |
| 11243 | if (!TSI) |
| 11244 | return ExprError(); |
| 11245 | |
| 11246 | ExprResult Sub = getDerived().TransformExpr(BCE->getSubExpr()); |
| 11247 | if (Sub.isInvalid()) |
| 11248 | return ExprError(); |
| 11249 | |
| 11250 | return getDerived().RebuildBuiltinBitCastExpr(BCE->getBeginLoc(), TSI, |
| 11251 | Sub.get(), BCE->getEndLoc()); |
| 11252 | } |
| 11253 | |
| 11254 | template<typename Derived> |
| 11255 | ExprResult |
| 11256 | TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { |
| 11257 | return getDerived().TransformCXXNamedCastExpr(E); |
| 11258 | } |
| 11259 | |
| 11260 | template<typename Derived> |
| 11261 | ExprResult |
| 11262 | TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { |
| 11263 | return getDerived().TransformCXXNamedCastExpr(E); |
| 11264 | } |
| 11265 | |
| 11266 | template<typename Derived> |
| 11267 | ExprResult |
| 11268 | TreeTransform<Derived>::TransformCXXReinterpretCastExpr( |
| 11269 | CXXReinterpretCastExpr *E) { |
| 11270 | return getDerived().TransformCXXNamedCastExpr(E); |
| 11271 | } |
| 11272 | |
| 11273 | template<typename Derived> |
| 11274 | ExprResult |
| 11275 | TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { |
| 11276 | return getDerived().TransformCXXNamedCastExpr(E); |
| 11277 | } |
| 11278 | |
| 11279 | template<typename Derived> |
| 11280 | ExprResult |
| 11281 | TreeTransform<Derived>::TransformCXXAddrspaceCastExpr(CXXAddrspaceCastExpr *E) { |
| 11282 | return getDerived().TransformCXXNamedCastExpr(E); |
| 11283 | } |
| 11284 | |
| 11285 | template<typename Derived> |
| 11286 | ExprResult |
| 11287 | TreeTransform<Derived>::TransformCXXFunctionalCastExpr( |
| 11288 | CXXFunctionalCastExpr *E) { |
| 11289 | TypeSourceInfo *Type = |
| 11290 | getDerived().TransformTypeWithDeducedTST(E->getTypeInfoAsWritten()); |
| 11291 | if (!Type) |
| 11292 | return ExprError(); |
| 11293 | |
| 11294 | ExprResult SubExpr |
| 11295 | = getDerived().TransformExpr(E->getSubExprAsWritten()); |
| 11296 | if (SubExpr.isInvalid()) |
| 11297 | return ExprError(); |
| 11298 | |
| 11299 | if (!getDerived().AlwaysRebuild() && |
| 11300 | Type == E->getTypeInfoAsWritten() && |
| 11301 | SubExpr.get() == E->getSubExpr()) |
| 11302 | return E; |
| 11303 | |
| 11304 | return getDerived().RebuildCXXFunctionalCastExpr(Type, |
| 11305 | E->getLParenLoc(), |
| 11306 | SubExpr.get(), |
| 11307 | E->getRParenLoc(), |
| 11308 | E->isListInitialization()); |
| 11309 | } |
| 11310 | |
| 11311 | template<typename Derived> |
| 11312 | ExprResult |
| 11313 | TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { |
| 11314 | if (E->isTypeOperand()) { |
| 11315 | TypeSourceInfo *TInfo |
| 11316 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 11317 | if (!TInfo) |
| 11318 | return ExprError(); |
| 11319 | |
| 11320 | if (!getDerived().AlwaysRebuild() && |
| 11321 | TInfo == E->getTypeOperandSourceInfo()) |
| 11322 | return E; |
| 11323 | |
| 11324 | return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), |
| 11325 | TInfo, E->getEndLoc()); |
| 11326 | } |
| 11327 | |
| 11328 | // We don't know whether the subexpression is potentially evaluated until |
| 11329 | // after we perform semantic analysis. We speculatively assume it is |
| 11330 | // unevaluated; it will get fixed later if the subexpression is in fact |
| 11331 | // potentially evaluated. |
| 11332 | EnterExpressionEvaluationContext Unevaluated( |
| 11333 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated, |
| 11334 | Sema::ReuseLambdaContextDecl); |
| 11335 | |
| 11336 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 11337 | if (SubExpr.isInvalid()) |
| 11338 | return ExprError(); |
| 11339 | |
| 11340 | if (!getDerived().AlwaysRebuild() && |
| 11341 | SubExpr.get() == E->getExprOperand()) |
| 11342 | return E; |
| 11343 | |
| 11344 | return getDerived().RebuildCXXTypeidExpr(E->getType(), E->getBeginLoc(), |
| 11345 | SubExpr.get(), E->getEndLoc()); |
| 11346 | } |
| 11347 | |
| 11348 | template<typename Derived> |
| 11349 | ExprResult |
| 11350 | TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { |
| 11351 | if (E->isTypeOperand()) { |
| 11352 | TypeSourceInfo *TInfo |
| 11353 | = getDerived().TransformType(E->getTypeOperandSourceInfo()); |
| 11354 | if (!TInfo) |
| 11355 | return ExprError(); |
| 11356 | |
| 11357 | if (!getDerived().AlwaysRebuild() && |
| 11358 | TInfo == E->getTypeOperandSourceInfo()) |
| 11359 | return E; |
| 11360 | |
| 11361 | return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), |
| 11362 | TInfo, E->getEndLoc()); |
| 11363 | } |
| 11364 | |
| 11365 | EnterExpressionEvaluationContext Unevaluated( |
| 11366 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| 11367 | |
| 11368 | ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); |
| 11369 | if (SubExpr.isInvalid()) |
| 11370 | return ExprError(); |
| 11371 | |
| 11372 | if (!getDerived().AlwaysRebuild() && |
| 11373 | SubExpr.get() == E->getExprOperand()) |
| 11374 | return E; |
| 11375 | |
| 11376 | return getDerived().RebuildCXXUuidofExpr(E->getType(), E->getBeginLoc(), |
| 11377 | SubExpr.get(), E->getEndLoc()); |
| 11378 | } |
| 11379 | |
| 11380 | template<typename Derived> |
| 11381 | ExprResult |
| 11382 | TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { |
| 11383 | return E; |
| 11384 | } |
| 11385 | |
| 11386 | template<typename Derived> |
| 11387 | ExprResult |
| 11388 | TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( |
| 11389 | CXXNullPtrLiteralExpr *E) { |
| 11390 | return E; |
| 11391 | } |
| 11392 | |
| 11393 | template<typename Derived> |
| 11394 | ExprResult |
| 11395 | TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { |
| 11396 | QualType T = getSema().getCurrentThisType(); |
| 11397 | |
| 11398 | if (!getDerived().AlwaysRebuild() && T == E->getType()) { |
| 11399 | // Mark it referenced in the new context regardless. |
| 11400 | // FIXME: this is a bit instantiation-specific. |
| 11401 | getSema().MarkThisReferenced(E); |
| 11402 | return E; |
| 11403 | } |
| 11404 | |
| 11405 | return getDerived().RebuildCXXThisExpr(E->getBeginLoc(), T, E->isImplicit()); |
| 11406 | } |
| 11407 | |
| 11408 | template<typename Derived> |
| 11409 | ExprResult |
| 11410 | TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { |
| 11411 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 11412 | if (SubExpr.isInvalid()) |
| 11413 | return ExprError(); |
| 11414 | |
| 11415 | if (!getDerived().AlwaysRebuild() && |
| 11416 | SubExpr.get() == E->getSubExpr()) |
| 11417 | return E; |
| 11418 | |
| 11419 | return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), |
| 11420 | E->isThrownVariableInScope()); |
| 11421 | } |
| 11422 | |
| 11423 | template<typename Derived> |
| 11424 | ExprResult |
| 11425 | TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { |
| 11426 | ParmVarDecl *Param = cast_or_null<ParmVarDecl>( |
| 11427 | getDerived().TransformDecl(E->getBeginLoc(), E->getParam())); |
| 11428 | if (!Param) |
| 11429 | return ExprError(); |
| 11430 | |
| 11431 | if (!getDerived().AlwaysRebuild() && Param == E->getParam() && |
| 11432 | E->getUsedContext() == SemaRef.CurContext) |
| 11433 | return E; |
| 11434 | |
| 11435 | return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); |
| 11436 | } |
| 11437 | |
| 11438 | template<typename Derived> |
| 11439 | ExprResult |
| 11440 | TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) { |
| 11441 | FieldDecl *Field = cast_or_null<FieldDecl>( |
| 11442 | getDerived().TransformDecl(E->getBeginLoc(), E->getField())); |
| 11443 | if (!Field) |
| 11444 | return ExprError(); |
| 11445 | |
| 11446 | if (!getDerived().AlwaysRebuild() && Field == E->getField() && |
| 11447 | E->getUsedContext() == SemaRef.CurContext) |
| 11448 | return E; |
| 11449 | |
| 11450 | return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field); |
| 11451 | } |
| 11452 | |
| 11453 | template<typename Derived> |
| 11454 | ExprResult |
| 11455 | TreeTransform<Derived>::TransformCXXScalarValueInitExpr( |
| 11456 | CXXScalarValueInitExpr *E) { |
| 11457 | TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); |
| 11458 | if (!T) |
| 11459 | return ExprError(); |
| 11460 | |
| 11461 | if (!getDerived().AlwaysRebuild() && |
| 11462 | T == E->getTypeSourceInfo()) |
| 11463 | return E; |
| 11464 | |
| 11465 | return getDerived().RebuildCXXScalarValueInitExpr(T, |
| 11466 | /*FIXME:*/T->getTypeLoc().getEndLoc(), |
| 11467 | E->getRParenLoc()); |
| 11468 | } |
| 11469 | |
| 11470 | template<typename Derived> |
| 11471 | ExprResult |
| 11472 | TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { |
| 11473 | // Transform the type that we're allocating |
| 11474 | TypeSourceInfo *AllocTypeInfo = |
| 11475 | getDerived().TransformTypeWithDeducedTST(E->getAllocatedTypeSourceInfo()); |
| 11476 | if (!AllocTypeInfo) |
| 11477 | return ExprError(); |
| 11478 | |
| 11479 | // Transform the size of the array we're allocating (if any). |
| 11480 | Optional<Expr *> ArraySize; |
| 11481 | if (Optional<Expr *> OldArraySize = E->getArraySize()) { |
| 11482 | ExprResult NewArraySize; |
| 11483 | if (*OldArraySize) { |
| 11484 | NewArraySize = getDerived().TransformExpr(*OldArraySize); |
| 11485 | if (NewArraySize.isInvalid()) |
| 11486 | return ExprError(); |
| 11487 | } |
| 11488 | ArraySize = NewArraySize.get(); |
| 11489 | } |
| 11490 | |
| 11491 | // Transform the placement arguments (if any). |
| 11492 | bool ArgumentChanged = false; |
| 11493 | SmallVector<Expr*, 8> PlacementArgs; |
| 11494 | if (getDerived().TransformExprs(E->getPlacementArgs(), |
| 11495 | E->getNumPlacementArgs(), true, |
| 11496 | PlacementArgs, &ArgumentChanged)) |
| 11497 | return ExprError(); |
| 11498 | |
| 11499 | // Transform the initializer (if any). |
| 11500 | Expr *OldInit = E->getInitializer(); |
| 11501 | ExprResult NewInit; |
| 11502 | if (OldInit) |
| 11503 | NewInit = getDerived().TransformInitializer(OldInit, true); |
| 11504 | if (NewInit.isInvalid()) |
| 11505 | return ExprError(); |
| 11506 | |
| 11507 | // Transform new operator and delete operator. |
| 11508 | FunctionDecl *OperatorNew = nullptr; |
| 11509 | if (E->getOperatorNew()) { |
| 11510 | OperatorNew = cast_or_null<FunctionDecl>( |
| 11511 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorNew())); |
| 11512 | if (!OperatorNew) |
| 11513 | return ExprError(); |
| 11514 | } |
| 11515 | |
| 11516 | FunctionDecl *OperatorDelete = nullptr; |
| 11517 | if (E->getOperatorDelete()) { |
| 11518 | OperatorDelete = cast_or_null<FunctionDecl>( |
| 11519 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); |
| 11520 | if (!OperatorDelete) |
| 11521 | return ExprError(); |
| 11522 | } |
| 11523 | |
| 11524 | if (!getDerived().AlwaysRebuild() && |
| 11525 | AllocTypeInfo == E->getAllocatedTypeSourceInfo() && |
| 11526 | ArraySize == E->getArraySize() && |
| 11527 | NewInit.get() == OldInit && |
| 11528 | OperatorNew == E->getOperatorNew() && |
| 11529 | OperatorDelete == E->getOperatorDelete() && |
| 11530 | !ArgumentChanged) { |
| 11531 | // Mark any declarations we need as referenced. |
| 11532 | // FIXME: instantiation-specific. |
| 11533 | if (OperatorNew) |
| 11534 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorNew); |
| 11535 | if (OperatorDelete) |
| 11536 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); |
| 11537 | |
| 11538 | if (E->isArray() && !E->getAllocatedType()->isDependentType()) { |
| 11539 | QualType ElementType |
| 11540 | = SemaRef.Context.getBaseElementType(E->getAllocatedType()); |
| 11541 | if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { |
| 11542 | CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); |
| 11543 | if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { |
| 11544 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Destructor); |
| 11545 | } |
| 11546 | } |
| 11547 | } |
| 11548 | |
| 11549 | return E; |
| 11550 | } |
| 11551 | |
| 11552 | QualType AllocType = AllocTypeInfo->getType(); |
| 11553 | if (!ArraySize) { |
| 11554 | // If no array size was specified, but the new expression was |
| 11555 | // instantiated with an array type (e.g., "new T" where T is |
| 11556 | // instantiated with "int[4]"), extract the outer bound from the |
| 11557 | // array type as our array size. We do this with constant and |
| 11558 | // dependently-sized array types. |
| 11559 | const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); |
| 11560 | if (!ArrayT) { |
| 11561 | // Do nothing |
| 11562 | } else if (const ConstantArrayType *ConsArrayT |
| 11563 | = dyn_cast<ConstantArrayType>(ArrayT)) { |
| 11564 | ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(), |
| 11565 | SemaRef.Context.getSizeType(), |
| 11566 | /*FIXME:*/ E->getBeginLoc()); |
| 11567 | AllocType = ConsArrayT->getElementType(); |
| 11568 | } else if (const DependentSizedArrayType *DepArrayT |
| 11569 | = dyn_cast<DependentSizedArrayType>(ArrayT)) { |
| 11570 | if (DepArrayT->getSizeExpr()) { |
| 11571 | ArraySize = DepArrayT->getSizeExpr(); |
| 11572 | AllocType = DepArrayT->getElementType(); |
| 11573 | } |
| 11574 | } |
| 11575 | } |
| 11576 | |
| 11577 | return getDerived().RebuildCXXNewExpr( |
| 11578 | E->getBeginLoc(), E->isGlobalNew(), |
| 11579 | /*FIXME:*/ E->getBeginLoc(), PlacementArgs, |
| 11580 | /*FIXME:*/ E->getBeginLoc(), E->getTypeIdParens(), AllocType, |
| 11581 | AllocTypeInfo, ArraySize, E->getDirectInitRange(), NewInit.get()); |
| 11582 | } |
| 11583 | |
| 11584 | template<typename Derived> |
| 11585 | ExprResult |
| 11586 | TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { |
| 11587 | ExprResult Operand = getDerived().TransformExpr(E->getArgument()); |
| 11588 | if (Operand.isInvalid()) |
| 11589 | return ExprError(); |
| 11590 | |
| 11591 | // Transform the delete operator, if known. |
| 11592 | FunctionDecl *OperatorDelete = nullptr; |
| 11593 | if (E->getOperatorDelete()) { |
| 11594 | OperatorDelete = cast_or_null<FunctionDecl>( |
| 11595 | getDerived().TransformDecl(E->getBeginLoc(), E->getOperatorDelete())); |
| 11596 | if (!OperatorDelete) |
| 11597 | return ExprError(); |
| 11598 | } |
| 11599 | |
| 11600 | if (!getDerived().AlwaysRebuild() && |
| 11601 | Operand.get() == E->getArgument() && |
| 11602 | OperatorDelete == E->getOperatorDelete()) { |
| 11603 | // Mark any declarations we need as referenced. |
| 11604 | // FIXME: instantiation-specific. |
| 11605 | if (OperatorDelete) |
| 11606 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), OperatorDelete); |
| 11607 | |
| 11608 | if (!E->getArgument()->isTypeDependent()) { |
| 11609 | QualType Destroyed = SemaRef.Context.getBaseElementType( |
| 11610 | E->getDestroyedType()); |
| 11611 | if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { |
| 11612 | CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); |
| 11613 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), |
| 11614 | SemaRef.LookupDestructor(Record)); |
| 11615 | } |
| 11616 | } |
| 11617 | |
| 11618 | return E; |
| 11619 | } |
| 11620 | |
| 11621 | return getDerived().RebuildCXXDeleteExpr( |
| 11622 | E->getBeginLoc(), E->isGlobalDelete(), E->isArrayForm(), Operand.get()); |
| 11623 | } |
| 11624 | |
| 11625 | template<typename Derived> |
| 11626 | ExprResult |
| 11627 | TreeTransform<Derived>::TransformCXXPseudoDestructorExpr( |
| 11628 | CXXPseudoDestructorExpr *E) { |
| 11629 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 11630 | if (Base.isInvalid()) |
| 11631 | return ExprError(); |
| 11632 | |
| 11633 | ParsedType ObjectTypePtr; |
| 11634 | bool MayBePseudoDestructor = false; |
| 11635 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
| 11636 | E->getOperatorLoc(), |
| 11637 | E->isArrow()? tok::arrow : tok::period, |
| 11638 | ObjectTypePtr, |
| 11639 | MayBePseudoDestructor); |
| 11640 | if (Base.isInvalid()) |
| 11641 | return ExprError(); |
| 11642 | |
| 11643 | QualType ObjectType = ObjectTypePtr.get(); |
| 11644 | NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); |
| 11645 | if (QualifierLoc) { |
| 11646 | QualifierLoc |
| 11647 | = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); |
| 11648 | if (!QualifierLoc) |
| 11649 | return ExprError(); |
| 11650 | } |
| 11651 | CXXScopeSpec SS; |
| 11652 | SS.Adopt(QualifierLoc); |
| 11653 | |
| 11654 | PseudoDestructorTypeStorage Destroyed; |
| 11655 | if (E->getDestroyedTypeInfo()) { |
| 11656 | TypeSourceInfo *DestroyedTypeInfo |
| 11657 | = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), |
| 11658 | ObjectType, nullptr, SS); |
| 11659 | if (!DestroyedTypeInfo) |
| 11660 | return ExprError(); |
| 11661 | Destroyed = DestroyedTypeInfo; |
| 11662 | } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { |
| 11663 | // We aren't likely to be able to resolve the identifier down to a type |
| 11664 | // now anyway, so just retain the identifier. |
| 11665 | Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), |
| 11666 | E->getDestroyedTypeLoc()); |
| 11667 | } else { |
| 11668 | // Look for a destructor known with the given name. |
| 11669 | ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), |
| 11670 | *E->getDestroyedTypeIdentifier(), |
| 11671 | E->getDestroyedTypeLoc(), |
| 11672 | /*Scope=*/nullptr, |
| 11673 | SS, ObjectTypePtr, |
| 11674 | false); |
| 11675 | if (!T) |
| 11676 | return ExprError(); |
| 11677 | |
| 11678 | Destroyed |
| 11679 | = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), |
| 11680 | E->getDestroyedTypeLoc()); |
| 11681 | } |
| 11682 | |
| 11683 | TypeSourceInfo *ScopeTypeInfo = nullptr; |
| 11684 | if (E->getScopeTypeInfo()) { |
| 11685 | CXXScopeSpec EmptySS; |
| 11686 | ScopeTypeInfo = getDerived().TransformTypeInObjectScope( |
| 11687 | E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS); |
| 11688 | if (!ScopeTypeInfo) |
| 11689 | return ExprError(); |
| 11690 | } |
| 11691 | |
| 11692 | return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), |
| 11693 | E->getOperatorLoc(), |
| 11694 | E->isArrow(), |
| 11695 | SS, |
| 11696 | ScopeTypeInfo, |
| 11697 | E->getColonColonLoc(), |
| 11698 | E->getTildeLoc(), |
| 11699 | Destroyed); |
| 11700 | } |
| 11701 | |
| 11702 | template <typename Derived> |
| 11703 | bool TreeTransform<Derived>::TransformOverloadExprDecls(OverloadExpr *Old, |
| 11704 | bool RequiresADL, |
| 11705 | LookupResult &R) { |
| 11706 | // Transform all the decls. |
| 11707 | bool AllEmptyPacks = true; |
| 11708 | for (auto *OldD : Old->decls()) { |
| 11709 | Decl *InstD = getDerived().TransformDecl(Old->getNameLoc(), OldD); |
| 11710 | if (!InstD) { |
| 11711 | // Silently ignore these if a UsingShadowDecl instantiated to nothing. |
| 11712 | // This can happen because of dependent hiding. |
| 11713 | if (isa<UsingShadowDecl>(OldD)) |
| 11714 | continue; |
| 11715 | else { |
| 11716 | R.clear(); |
| 11717 | return true; |
| 11718 | } |
| 11719 | } |
| 11720 | |
| 11721 | // Expand using pack declarations. |
| 11722 | NamedDecl *SingleDecl = cast<NamedDecl>(InstD); |
| 11723 | ArrayRef<NamedDecl*> Decls = SingleDecl; |
| 11724 | if (auto *UPD = dyn_cast<UsingPackDecl>(InstD)) |
| 11725 | Decls = UPD->expansions(); |
| 11726 | |
| 11727 | // Expand using declarations. |
| 11728 | for (auto *D : Decls) { |
| 11729 | if (auto *UD = dyn_cast<UsingDecl>(D)) { |
| 11730 | for (auto *SD : UD->shadows()) |
| 11731 | R.addDecl(SD); |
| 11732 | } else { |
| 11733 | R.addDecl(D); |
| 11734 | } |
| 11735 | } |
| 11736 | |
| 11737 | AllEmptyPacks &= Decls.empty(); |
| 11738 | }; |
| 11739 | |
| 11740 | // C++ [temp.res]/8.4.2: |
| 11741 | // The program is ill-formed, no diagnostic required, if [...] lookup for |
| 11742 | // a name in the template definition found a using-declaration, but the |
| 11743 | // lookup in the corresponding scope in the instantiation odoes not find |
| 11744 | // any declarations because the using-declaration was a pack expansion and |
| 11745 | // the corresponding pack is empty |
| 11746 | if (AllEmptyPacks && !RequiresADL) { |
| 11747 | getSema().Diag(Old->getNameLoc(), diag::err_using_pack_expansion_empty) |
| 11748 | << isa<UnresolvedMemberExpr>(Old) << Old->getName(); |
| 11749 | return true; |
| 11750 | } |
| 11751 | |
| 11752 | // Resolve a kind, but don't do any further analysis. If it's |
| 11753 | // ambiguous, the callee needs to deal with it. |
| 11754 | R.resolveKind(); |
| 11755 | return false; |
| 11756 | } |
| 11757 | |
| 11758 | template<typename Derived> |
| 11759 | ExprResult |
| 11760 | TreeTransform<Derived>::TransformUnresolvedLookupExpr( |
| 11761 | UnresolvedLookupExpr *Old) { |
| 11762 | LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), |
| 11763 | Sema::LookupOrdinaryName); |
| 11764 | |
| 11765 | // Transform the declaration set. |
| 11766 | if (TransformOverloadExprDecls(Old, Old->requiresADL(), R)) |
| 11767 | return ExprError(); |
| 11768 | |
| 11769 | // Rebuild the nested-name qualifier, if present. |
| 11770 | CXXScopeSpec SS; |
| 11771 | if (Old->getQualifierLoc()) { |
| 11772 | NestedNameSpecifierLoc QualifierLoc |
| 11773 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 11774 | if (!QualifierLoc) |
| 11775 | return ExprError(); |
| 11776 | |
| 11777 | SS.Adopt(QualifierLoc); |
| 11778 | } |
| 11779 | |
| 11780 | if (Old->getNamingClass()) { |
| 11781 | CXXRecordDecl *NamingClass |
| 11782 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 11783 | Old->getNameLoc(), |
| 11784 | Old->getNamingClass())); |
| 11785 | if (!NamingClass) { |
| 11786 | R.clear(); |
| 11787 | return ExprError(); |
| 11788 | } |
| 11789 | |
| 11790 | R.setNamingClass(NamingClass); |
| 11791 | } |
| 11792 | |
| 11793 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 11794 | |
| 11795 | // If we have neither explicit template arguments, nor the template keyword, |
| 11796 | // it's a normal declaration name or member reference. |
| 11797 | if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) { |
| 11798 | NamedDecl *D = R.getAsSingle<NamedDecl>(); |
| 11799 | // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an |
| 11800 | // instance member. In other contexts, BuildPossibleImplicitMemberExpr will |
| 11801 | // give a good diagnostic. |
| 11802 | if (D && D->isCXXInstanceMember()) { |
| 11803 | return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R, |
| 11804 | /*TemplateArgs=*/nullptr, |
| 11805 | /*Scope=*/nullptr); |
| 11806 | } |
| 11807 | |
| 11808 | return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); |
| 11809 | } |
| 11810 | |
| 11811 | // If we have template arguments, rebuild them, then rebuild the |
| 11812 | // templateid expression. |
| 11813 | TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); |
| 11814 | if (Old->hasExplicitTemplateArgs() && |
| 11815 | getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 11816 | Old->getNumTemplateArgs(), |
| 11817 | TransArgs)) { |
| 11818 | R.clear(); |
| 11819 | return ExprError(); |
| 11820 | } |
| 11821 | |
| 11822 | return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, |
| 11823 | Old->requiresADL(), &TransArgs); |
| 11824 | } |
| 11825 | |
| 11826 | template<typename Derived> |
| 11827 | ExprResult |
| 11828 | TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { |
| 11829 | bool ArgChanged = false; |
| 11830 | SmallVector<TypeSourceInfo *, 4> Args; |
| 11831 | for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { |
| 11832 | TypeSourceInfo *From = E->getArg(I); |
| 11833 | TypeLoc FromTL = From->getTypeLoc(); |
| 11834 | if (!FromTL.getAs<PackExpansionTypeLoc>()) { |
| 11835 | TypeLocBuilder TLB; |
| 11836 | TLB.reserve(FromTL.getFullDataSize()); |
| 11837 | QualType To = getDerived().TransformType(TLB, FromTL); |
| 11838 | if (To.isNull()) |
| 11839 | return ExprError(); |
| 11840 | |
| 11841 | if (To == From->getType()) |
| 11842 | Args.push_back(From); |
| 11843 | else { |
| 11844 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 11845 | ArgChanged = true; |
| 11846 | } |
| 11847 | continue; |
| 11848 | } |
| 11849 | |
| 11850 | ArgChanged = true; |
| 11851 | |
| 11852 | // We have a pack expansion. Instantiate it. |
| 11853 | PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>(); |
| 11854 | TypeLoc PatternTL = ExpansionTL.getPatternLoc(); |
| 11855 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 11856 | SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); |
| 11857 | |
| 11858 | // Determine whether the set of unexpanded parameter packs can and should |
| 11859 | // be expanded. |
| 11860 | bool Expand = true; |
| 11861 | bool RetainExpansion = false; |
| 11862 | Optional<unsigned> OrigNumExpansions = |
| 11863 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 11864 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 11865 | if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), |
| 11866 | PatternTL.getSourceRange(), |
| 11867 | Unexpanded, |
| 11868 | Expand, RetainExpansion, |
| 11869 | NumExpansions)) |
| 11870 | return ExprError(); |
| 11871 | |
| 11872 | if (!Expand) { |
| 11873 | // The transform has determined that we should perform a simple |
| 11874 | // transformation on the pack expansion, producing another pack |
| 11875 | // expansion. |
| 11876 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 11877 | |
| 11878 | TypeLocBuilder TLB; |
| 11879 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 11880 | |
| 11881 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 11882 | if (To.isNull()) |
| 11883 | return ExprError(); |
| 11884 | |
| 11885 | To = getDerived().RebuildPackExpansionType(To, |
| 11886 | PatternTL.getSourceRange(), |
| 11887 | ExpansionTL.getEllipsisLoc(), |
| 11888 | NumExpansions); |
| 11889 | if (To.isNull()) |
| 11890 | return ExprError(); |
| 11891 | |
| 11892 | PackExpansionTypeLoc ToExpansionTL |
| 11893 | = TLB.push<PackExpansionTypeLoc>(To); |
| 11894 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 11895 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 11896 | continue; |
| 11897 | } |
| 11898 | |
| 11899 | // Expand the pack expansion by substituting for each argument in the |
| 11900 | // pack(s). |
| 11901 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 11902 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); |
| 11903 | TypeLocBuilder TLB; |
| 11904 | TLB.reserve(PatternTL.getFullDataSize()); |
| 11905 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 11906 | if (To.isNull()) |
| 11907 | return ExprError(); |
| 11908 | |
| 11909 | if (To->containsUnexpandedParameterPack()) { |
| 11910 | To = getDerived().RebuildPackExpansionType(To, |
| 11911 | PatternTL.getSourceRange(), |
| 11912 | ExpansionTL.getEllipsisLoc(), |
| 11913 | NumExpansions); |
| 11914 | if (To.isNull()) |
| 11915 | return ExprError(); |
| 11916 | |
| 11917 | PackExpansionTypeLoc ToExpansionTL |
| 11918 | = TLB.push<PackExpansionTypeLoc>(To); |
| 11919 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 11920 | } |
| 11921 | |
| 11922 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 11923 | } |
| 11924 | |
| 11925 | if (!RetainExpansion) |
| 11926 | continue; |
| 11927 | |
| 11928 | // If we're supposed to retain a pack expansion, do so by temporarily |
| 11929 | // forgetting the partially-substituted parameter pack. |
| 11930 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 11931 | |
| 11932 | TypeLocBuilder TLB; |
| 11933 | TLB.reserve(From->getTypeLoc().getFullDataSize()); |
| 11934 | |
| 11935 | QualType To = getDerived().TransformType(TLB, PatternTL); |
| 11936 | if (To.isNull()) |
| 11937 | return ExprError(); |
| 11938 | |
| 11939 | To = getDerived().RebuildPackExpansionType(To, |
| 11940 | PatternTL.getSourceRange(), |
| 11941 | ExpansionTL.getEllipsisLoc(), |
| 11942 | NumExpansions); |
| 11943 | if (To.isNull()) |
| 11944 | return ExprError(); |
| 11945 | |
| 11946 | PackExpansionTypeLoc ToExpansionTL |
| 11947 | = TLB.push<PackExpansionTypeLoc>(To); |
| 11948 | ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); |
| 11949 | Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); |
| 11950 | } |
| 11951 | |
| 11952 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 11953 | return E; |
| 11954 | |
| 11955 | return getDerived().RebuildTypeTrait(E->getTrait(), E->getBeginLoc(), Args, |
| 11956 | E->getEndLoc()); |
| 11957 | } |
| 11958 | |
| 11959 | template<typename Derived> |
| 11960 | ExprResult |
| 11961 | TreeTransform<Derived>::TransformConceptSpecializationExpr( |
| 11962 | ConceptSpecializationExpr *E) { |
| 11963 | const ASTTemplateArgumentListInfo *Old = E->getTemplateArgsAsWritten(); |
| 11964 | TemplateArgumentListInfo TransArgs(Old->LAngleLoc, Old->RAngleLoc); |
| 11965 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 11966 | Old->NumTemplateArgs, TransArgs)) |
| 11967 | return ExprError(); |
| 11968 | |
| 11969 | return getDerived().RebuildConceptSpecializationExpr( |
| 11970 | E->getNestedNameSpecifierLoc(), E->getTemplateKWLoc(), |
| 11971 | E->getConceptNameInfo(), E->getFoundDecl(), E->getNamedConcept(), |
| 11972 | &TransArgs); |
| 11973 | } |
| 11974 | |
| 11975 | template<typename Derived> |
| 11976 | ExprResult |
| 11977 | TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) { |
| 11978 | SmallVector<ParmVarDecl*, 4> TransParams; |
| 11979 | SmallVector<QualType, 4> TransParamTypes; |
| 11980 | Sema::ExtParameterInfoBuilder ExtParamInfos; |
| 11981 | |
| 11982 | // C++2a [expr.prim.req]p2 |
| 11983 | // Expressions appearing within a requirement-body are unevaluated operands. |
| 11984 | EnterExpressionEvaluationContext Ctx( |
| 11985 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| 11986 | |
| 11987 | RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create( |
| 11988 | getSema().Context, getSema().CurContext, |
| 11989 | E->getBody()->getBeginLoc()); |
| 11990 | |
| 11991 | Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false); |
| 11992 | |
| 11993 | if (getDerived().TransformFunctionTypeParams(E->getRequiresKWLoc(), |
| 11994 | E->getLocalParameters(), |
| 11995 | /*ParamTypes=*/nullptr, |
| 11996 | /*ParamInfos=*/nullptr, |
| 11997 | TransParamTypes, &TransParams, |
| 11998 | ExtParamInfos)) |
| 11999 | return ExprError(); |
| 12000 | |
| 12001 | for (ParmVarDecl *Param : TransParams) |
| 12002 | Param->setDeclContext(Body); |
| 12003 | |
| 12004 | SmallVector<concepts::Requirement *, 4> TransReqs; |
| 12005 | if (getDerived().TransformRequiresExprRequirements(E->getRequirements(), |
| 12006 | TransReqs)) |
| 12007 | return ExprError(); |
| 12008 | |
| 12009 | for (concepts::Requirement *Req : TransReqs) { |
| 12010 | if (auto *ER = dyn_cast<concepts::ExprRequirement>(Req)) { |
| 12011 | if (ER->getReturnTypeRequirement().isTypeConstraint()) { |
| 12012 | ER->getReturnTypeRequirement() |
| 12013 | .getTypeConstraintTemplateParameterList()->getParam(0) |
| 12014 | ->setDeclContext(Body); |
| 12015 | } |
| 12016 | } |
| 12017 | } |
| 12018 | |
| 12019 | return getDerived().RebuildRequiresExpr(E->getRequiresKWLoc(), Body, |
| 12020 | TransParams, TransReqs, |
| 12021 | E->getRBraceLoc()); |
| 12022 | } |
| 12023 | |
| 12024 | template<typename Derived> |
| 12025 | bool TreeTransform<Derived>::TransformRequiresExprRequirements( |
| 12026 | ArrayRef<concepts::Requirement *> Reqs, |
| 12027 | SmallVectorImpl<concepts::Requirement *> &Transformed) { |
| 12028 | for (concepts::Requirement *Req : Reqs) { |
| 12029 | concepts::Requirement *TransReq = nullptr; |
| 12030 | if (auto *TypeReq = dyn_cast<concepts::TypeRequirement>(Req)) |
| 12031 | TransReq = getDerived().TransformTypeRequirement(TypeReq); |
| 12032 | else if (auto *ExprReq = dyn_cast<concepts::ExprRequirement>(Req)) |
| 12033 | TransReq = getDerived().TransformExprRequirement(ExprReq); |
| 12034 | else |
| 12035 | TransReq = getDerived().TransformNestedRequirement( |
| 12036 | cast<concepts::NestedRequirement>(Req)); |
| 12037 | if (!TransReq) |
| 12038 | return true; |
| 12039 | Transformed.push_back(TransReq); |
| 12040 | } |
| 12041 | return false; |
| 12042 | } |
| 12043 | |
| 12044 | template<typename Derived> |
| 12045 | concepts::TypeRequirement * |
| 12046 | TreeTransform<Derived>::TransformTypeRequirement( |
| 12047 | concepts::TypeRequirement *Req) { |
| 12048 | if (Req->isSubstitutionFailure()) { |
| 12049 | if (getDerived().AlwaysRebuild()) |
| 12050 | return getDerived().RebuildTypeRequirement( |
| 12051 | Req->getSubstitutionDiagnostic()); |
| 12052 | return Req; |
| 12053 | } |
| 12054 | TypeSourceInfo *TransType = getDerived().TransformType(Req->getType()); |
| 12055 | if (!TransType) |
| 12056 | return nullptr; |
| 12057 | return getDerived().RebuildTypeRequirement(TransType); |
| 12058 | } |
| 12059 | |
| 12060 | template<typename Derived> |
| 12061 | concepts::ExprRequirement * |
| 12062 | TreeTransform<Derived>::TransformExprRequirement(concepts::ExprRequirement *Req) { |
| 12063 | llvm::PointerUnion<Expr *, concepts::Requirement::SubstitutionDiagnostic *> TransExpr; |
| 12064 | if (Req->isExprSubstitutionFailure()) |
| 12065 | TransExpr = Req->getExprSubstitutionDiagnostic(); |
| 12066 | else { |
| 12067 | ExprResult TransExprRes = getDerived().TransformExpr(Req->getExpr()); |
| 12068 | if (TransExprRes.isInvalid()) |
| 12069 | return nullptr; |
| 12070 | TransExpr = TransExprRes.get(); |
| 12071 | } |
| 12072 | |
| 12073 | llvm::Optional<concepts::ExprRequirement::ReturnTypeRequirement> TransRetReq; |
| 12074 | const auto &RetReq = Req->getReturnTypeRequirement(); |
| 12075 | if (RetReq.isEmpty()) |
| 12076 | TransRetReq.emplace(); |
| 12077 | else if (RetReq.isSubstitutionFailure()) |
| 12078 | TransRetReq.emplace(RetReq.getSubstitutionDiagnostic()); |
| 12079 | else if (RetReq.isTypeConstraint()) { |
| 12080 | TemplateParameterList *OrigTPL = |
| 12081 | RetReq.getTypeConstraintTemplateParameterList(); |
| 12082 | TemplateParameterList *TPL = |
| 12083 | getDerived().TransformTemplateParameterList(OrigTPL); |
| 12084 | if (!TPL) |
| 12085 | return nullptr; |
| 12086 | TransRetReq.emplace(TPL); |
| 12087 | } |
| 12088 | assert(TransRetReq.hasValue() && |
| 12089 | "All code paths leading here must set TransRetReq" ); |
| 12090 | if (Expr *E = TransExpr.dyn_cast<Expr *>()) |
| 12091 | return getDerived().RebuildExprRequirement(E, Req->isSimple(), |
| 12092 | Req->getNoexceptLoc(), |
| 12093 | std::move(*TransRetReq)); |
| 12094 | return getDerived().RebuildExprRequirement( |
| 12095 | TransExpr.get<concepts::Requirement::SubstitutionDiagnostic *>(), |
| 12096 | Req->isSimple(), Req->getNoexceptLoc(), std::move(*TransRetReq)); |
| 12097 | } |
| 12098 | |
| 12099 | template<typename Derived> |
| 12100 | concepts::NestedRequirement * |
| 12101 | TreeTransform<Derived>::TransformNestedRequirement( |
| 12102 | concepts::NestedRequirement *Req) { |
| 12103 | if (Req->isSubstitutionFailure()) { |
| 12104 | if (getDerived().AlwaysRebuild()) |
| 12105 | return getDerived().RebuildNestedRequirement( |
| 12106 | Req->getSubstitutionDiagnostic()); |
| 12107 | return Req; |
| 12108 | } |
| 12109 | ExprResult TransConstraint = |
| 12110 | getDerived().TransformExpr(Req->getConstraintExpr()); |
| 12111 | if (TransConstraint.isInvalid()) |
| 12112 | return nullptr; |
| 12113 | return getDerived().RebuildNestedRequirement(TransConstraint.get()); |
| 12114 | } |
| 12115 | |
| 12116 | template<typename Derived> |
| 12117 | ExprResult |
| 12118 | TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { |
| 12119 | TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); |
| 12120 | if (!T) |
| 12121 | return ExprError(); |
| 12122 | |
| 12123 | if (!getDerived().AlwaysRebuild() && |
| 12124 | T == E->getQueriedTypeSourceInfo()) |
| 12125 | return E; |
| 12126 | |
| 12127 | ExprResult SubExpr; |
| 12128 | { |
| 12129 | EnterExpressionEvaluationContext Unevaluated( |
| 12130 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| 12131 | SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); |
| 12132 | if (SubExpr.isInvalid()) |
| 12133 | return ExprError(); |
| 12134 | |
| 12135 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) |
| 12136 | return E; |
| 12137 | } |
| 12138 | |
| 12139 | return getDerived().RebuildArrayTypeTrait(E->getTrait(), E->getBeginLoc(), T, |
| 12140 | SubExpr.get(), E->getEndLoc()); |
| 12141 | } |
| 12142 | |
| 12143 | template<typename Derived> |
| 12144 | ExprResult |
| 12145 | TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { |
| 12146 | ExprResult SubExpr; |
| 12147 | { |
| 12148 | EnterExpressionEvaluationContext Unevaluated( |
| 12149 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| 12150 | SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); |
| 12151 | if (SubExpr.isInvalid()) |
| 12152 | return ExprError(); |
| 12153 | |
| 12154 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) |
| 12155 | return E; |
| 12156 | } |
| 12157 | |
| 12158 | return getDerived().RebuildExpressionTrait(E->getTrait(), E->getBeginLoc(), |
| 12159 | SubExpr.get(), E->getEndLoc()); |
| 12160 | } |
| 12161 | |
| 12162 | template <typename Derived> |
| 12163 | ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr( |
| 12164 | ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken, |
| 12165 | TypeSourceInfo **RecoveryTSI) { |
| 12166 | ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr( |
| 12167 | DRE, AddrTaken, RecoveryTSI); |
| 12168 | |
| 12169 | // Propagate both errors and recovered types, which return ExprEmpty. |
| 12170 | if (!NewDRE.isUsable()) |
| 12171 | return NewDRE; |
| 12172 | |
| 12173 | // We got an expr, wrap it up in parens. |
| 12174 | if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE) |
| 12175 | return PE; |
| 12176 | return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(), |
| 12177 | PE->getRParen()); |
| 12178 | } |
| 12179 | |
| 12180 | template <typename Derived> |
| 12181 | ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 12182 | DependentScopeDeclRefExpr *E) { |
| 12183 | return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false, |
| 12184 | nullptr); |
| 12185 | } |
| 12186 | |
| 12187 | template<typename Derived> |
| 12188 | ExprResult |
| 12189 | TreeTransform<Derived>::TransformDependentScopeDeclRefExpr( |
| 12190 | DependentScopeDeclRefExpr *E, |
| 12191 | bool IsAddressOfOperand, |
| 12192 | TypeSourceInfo **RecoveryTSI) { |
| 12193 | assert(E->getQualifierLoc()); |
| 12194 | NestedNameSpecifierLoc QualifierLoc |
| 12195 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); |
| 12196 | if (!QualifierLoc) |
| 12197 | return ExprError(); |
| 12198 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 12199 | |
| 12200 | // TODO: If this is a conversion-function-id, verify that the |
| 12201 | // destination type name (if present) resolves the same way after |
| 12202 | // instantiation as it did in the local scope. |
| 12203 | |
| 12204 | DeclarationNameInfo NameInfo |
| 12205 | = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); |
| 12206 | if (!NameInfo.getName()) |
| 12207 | return ExprError(); |
| 12208 | |
| 12209 | if (!E->hasExplicitTemplateArgs()) { |
| 12210 | if (!getDerived().AlwaysRebuild() && |
| 12211 | QualifierLoc == E->getQualifierLoc() && |
| 12212 | // Note: it is sufficient to compare the Name component of NameInfo: |
| 12213 | // if name has not changed, DNLoc has not changed either. |
| 12214 | NameInfo.getName() == E->getDeclName()) |
| 12215 | return E; |
| 12216 | |
| 12217 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 12218 | QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr, |
| 12219 | IsAddressOfOperand, RecoveryTSI); |
| 12220 | } |
| 12221 | |
| 12222 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
| 12223 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 12224 | E->getNumTemplateArgs(), |
| 12225 | TransArgs)) |
| 12226 | return ExprError(); |
| 12227 | |
| 12228 | return getDerived().RebuildDependentScopeDeclRefExpr( |
| 12229 | QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand, |
| 12230 | RecoveryTSI); |
| 12231 | } |
| 12232 | |
| 12233 | template<typename Derived> |
| 12234 | ExprResult |
| 12235 | TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { |
| 12236 | // CXXConstructExprs other than for list-initialization and |
| 12237 | // CXXTemporaryObjectExpr are always implicit, so when we have |
| 12238 | // a 1-argument construction we just transform that argument. |
| 12239 | if (getDerived().AllowSkippingCXXConstructExpr() && |
| 12240 | ((E->getNumArgs() == 1 || |
| 12241 | (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) && |
| 12242 | (!getDerived().DropCallArgument(E->getArg(0))) && |
| 12243 | !E->isListInitialization())) |
| 12244 | return getDerived().TransformExpr(E->getArg(0)); |
| 12245 | |
| 12246 | TemporaryBase Rebase(*this, /*FIXME*/ E->getBeginLoc(), DeclarationName()); |
| 12247 | |
| 12248 | QualType T = getDerived().TransformType(E->getType()); |
| 12249 | if (T.isNull()) |
| 12250 | return ExprError(); |
| 12251 | |
| 12252 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 12253 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| 12254 | if (!Constructor) |
| 12255 | return ExprError(); |
| 12256 | |
| 12257 | bool ArgumentChanged = false; |
| 12258 | SmallVector<Expr*, 8> Args; |
| 12259 | { |
| 12260 | EnterExpressionEvaluationContext Context( |
| 12261 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 12262 | E->isListInitialization()); |
| 12263 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 12264 | &ArgumentChanged)) |
| 12265 | return ExprError(); |
| 12266 | } |
| 12267 | |
| 12268 | if (!getDerived().AlwaysRebuild() && |
| 12269 | T == E->getType() && |
| 12270 | Constructor == E->getConstructor() && |
| 12271 | !ArgumentChanged) { |
| 12272 | // Mark the constructor as referenced. |
| 12273 | // FIXME: Instantiation-specific |
| 12274 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| 12275 | return E; |
| 12276 | } |
| 12277 | |
| 12278 | return getDerived().RebuildCXXConstructExpr( |
| 12279 | T, /*FIXME:*/ E->getBeginLoc(), Constructor, E->isElidable(), Args, |
| 12280 | E->hadMultipleCandidates(), E->isListInitialization(), |
| 12281 | E->isStdInitListInitialization(), E->requiresZeroInitialization(), |
| 12282 | E->getConstructionKind(), E->getParenOrBraceRange()); |
| 12283 | } |
| 12284 | |
| 12285 | template<typename Derived> |
| 12286 | ExprResult TreeTransform<Derived>::TransformCXXInheritedCtorInitExpr( |
| 12287 | CXXInheritedCtorInitExpr *E) { |
| 12288 | QualType T = getDerived().TransformType(E->getType()); |
| 12289 | if (T.isNull()) |
| 12290 | return ExprError(); |
| 12291 | |
| 12292 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 12293 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| 12294 | if (!Constructor) |
| 12295 | return ExprError(); |
| 12296 | |
| 12297 | if (!getDerived().AlwaysRebuild() && |
| 12298 | T == E->getType() && |
| 12299 | Constructor == E->getConstructor()) { |
| 12300 | // Mark the constructor as referenced. |
| 12301 | // FIXME: Instantiation-specific |
| 12302 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| 12303 | return E; |
| 12304 | } |
| 12305 | |
| 12306 | return getDerived().RebuildCXXInheritedCtorInitExpr( |
| 12307 | T, E->getLocation(), Constructor, |
| 12308 | E->constructsVBase(), E->inheritedFromVBase()); |
| 12309 | } |
| 12310 | |
| 12311 | /// Transform a C++ temporary-binding expression. |
| 12312 | /// |
| 12313 | /// Since CXXBindTemporaryExpr nodes are implicitly generated, we just |
| 12314 | /// transform the subexpression and return that. |
| 12315 | template<typename Derived> |
| 12316 | ExprResult |
| 12317 | TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { |
| 12318 | return getDerived().TransformExpr(E->getSubExpr()); |
| 12319 | } |
| 12320 | |
| 12321 | /// Transform a C++ expression that contains cleanups that should |
| 12322 | /// be run after the expression is evaluated. |
| 12323 | /// |
| 12324 | /// Since ExprWithCleanups nodes are implicitly generated, we |
| 12325 | /// just transform the subexpression and return that. |
| 12326 | template<typename Derived> |
| 12327 | ExprResult |
| 12328 | TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { |
| 12329 | return getDerived().TransformExpr(E->getSubExpr()); |
| 12330 | } |
| 12331 | |
| 12332 | template<typename Derived> |
| 12333 | ExprResult |
| 12334 | TreeTransform<Derived>::TransformCXXTemporaryObjectExpr( |
| 12335 | CXXTemporaryObjectExpr *E) { |
| 12336 | TypeSourceInfo *T = |
| 12337 | getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); |
| 12338 | if (!T) |
| 12339 | return ExprError(); |
| 12340 | |
| 12341 | CXXConstructorDecl *Constructor = cast_or_null<CXXConstructorDecl>( |
| 12342 | getDerived().TransformDecl(E->getBeginLoc(), E->getConstructor())); |
| 12343 | if (!Constructor) |
| 12344 | return ExprError(); |
| 12345 | |
| 12346 | bool ArgumentChanged = false; |
| 12347 | SmallVector<Expr*, 8> Args; |
| 12348 | Args.reserve(E->getNumArgs()); |
| 12349 | { |
| 12350 | EnterExpressionEvaluationContext Context( |
| 12351 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 12352 | E->isListInitialization()); |
| 12353 | if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, |
| 12354 | &ArgumentChanged)) |
| 12355 | return ExprError(); |
| 12356 | } |
| 12357 | |
| 12358 | if (!getDerived().AlwaysRebuild() && |
| 12359 | T == E->getTypeSourceInfo() && |
| 12360 | Constructor == E->getConstructor() && |
| 12361 | !ArgumentChanged) { |
| 12362 | // FIXME: Instantiation-specific |
| 12363 | SemaRef.MarkFunctionReferenced(E->getBeginLoc(), Constructor); |
| 12364 | return SemaRef.MaybeBindToTemporary(E); |
| 12365 | } |
| 12366 | |
| 12367 | // FIXME: We should just pass E->isListInitialization(), but we're not |
| 12368 | // prepared to handle list-initialization without a child InitListExpr. |
| 12369 | SourceLocation LParenLoc = T->getTypeLoc().getEndLoc(); |
| 12370 | return getDerived().RebuildCXXTemporaryObjectExpr( |
| 12371 | T, LParenLoc, Args, E->getEndLoc(), |
| 12372 | /*ListInitialization=*/LParenLoc.isInvalid()); |
| 12373 | } |
| 12374 | |
| 12375 | template<typename Derived> |
| 12376 | ExprResult |
| 12377 | TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { |
| 12378 | // Transform any init-capture expressions before entering the scope of the |
| 12379 | // lambda body, because they are not semantically within that scope. |
| 12380 | typedef std::pair<ExprResult, QualType> InitCaptureInfoTy; |
| 12381 | struct TransformedInitCapture { |
| 12382 | // The location of the ... if the result is retaining a pack expansion. |
| 12383 | SourceLocation EllipsisLoc; |
| 12384 | // Zero or more expansions of the init-capture. |
| 12385 | SmallVector<InitCaptureInfoTy, 4> Expansions; |
| 12386 | }; |
| 12387 | SmallVector<TransformedInitCapture, 4> InitCaptures; |
| 12388 | InitCaptures.resize(E->explicit_capture_end() - E->explicit_capture_begin()); |
| 12389 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 12390 | CEnd = E->capture_end(); |
| 12391 | C != CEnd; ++C) { |
| 12392 | if (!E->isInitCapture(C)) |
| 12393 | continue; |
| 12394 | |
| 12395 | TransformedInitCapture &Result = InitCaptures[C - E->capture_begin()]; |
| 12396 | VarDecl *OldVD = C->getCapturedVar(); |
| 12397 | |
| 12398 | auto SubstInitCapture = [&](SourceLocation EllipsisLoc, |
| 12399 | Optional<unsigned> NumExpansions) { |
| 12400 | ExprResult NewExprInitResult = getDerived().TransformInitializer( |
| 12401 | OldVD->getInit(), OldVD->getInitStyle() == VarDecl::CallInit); |
| 12402 | |
| 12403 | if (NewExprInitResult.isInvalid()) { |
| 12404 | Result.Expansions.push_back(InitCaptureInfoTy(ExprError(), QualType())); |
| 12405 | return; |
| 12406 | } |
| 12407 | Expr *NewExprInit = NewExprInitResult.get(); |
| 12408 | |
| 12409 | QualType NewInitCaptureType = |
| 12410 | getSema().buildLambdaInitCaptureInitialization( |
| 12411 | C->getLocation(), OldVD->getType()->isReferenceType(), |
| 12412 | EllipsisLoc, NumExpansions, OldVD->getIdentifier(), |
| 12413 | C->getCapturedVar()->getInitStyle() != VarDecl::CInit, |
| 12414 | NewExprInit); |
| 12415 | Result.Expansions.push_back( |
| 12416 | InitCaptureInfoTy(NewExprInit, NewInitCaptureType)); |
| 12417 | }; |
| 12418 | |
| 12419 | // If this is an init-capture pack, consider expanding the pack now. |
| 12420 | if (OldVD->isParameterPack()) { |
| 12421 | PackExpansionTypeLoc ExpansionTL = OldVD->getTypeSourceInfo() |
| 12422 | ->getTypeLoc() |
| 12423 | .castAs<PackExpansionTypeLoc>(); |
| 12424 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 12425 | SemaRef.collectUnexpandedParameterPacks(OldVD->getInit(), Unexpanded); |
| 12426 | |
| 12427 | // Determine whether the set of unexpanded parameter packs can and should |
| 12428 | // be expanded. |
| 12429 | bool Expand = true; |
| 12430 | bool RetainExpansion = false; |
| 12431 | Optional<unsigned> OrigNumExpansions = |
| 12432 | ExpansionTL.getTypePtr()->getNumExpansions(); |
| 12433 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 12434 | if (getDerived().TryExpandParameterPacks( |
| 12435 | ExpansionTL.getEllipsisLoc(), |
| 12436 | OldVD->getInit()->getSourceRange(), Unexpanded, Expand, |
| 12437 | RetainExpansion, NumExpansions)) |
| 12438 | return ExprError(); |
| 12439 | if (Expand) { |
| 12440 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 12441 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 12442 | SubstInitCapture(SourceLocation(), None); |
| 12443 | } |
| 12444 | } |
| 12445 | if (!Expand || RetainExpansion) { |
| 12446 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 12447 | SubstInitCapture(ExpansionTL.getEllipsisLoc(), NumExpansions); |
| 12448 | Result.EllipsisLoc = ExpansionTL.getEllipsisLoc(); |
| 12449 | } |
| 12450 | } else { |
| 12451 | SubstInitCapture(SourceLocation(), None); |
| 12452 | } |
| 12453 | } |
| 12454 | |
| 12455 | LambdaScopeInfo *LSI = getSema().PushLambdaScope(); |
| 12456 | Sema::FunctionScopeRAII FuncScopeCleanup(getSema()); |
| 12457 | |
| 12458 | // Transform the template parameters, and add them to the current |
| 12459 | // instantiation scope. The null case is handled correctly. |
| 12460 | auto TPL = getDerived().TransformTemplateParameterList( |
| 12461 | E->getTemplateParameterList()); |
| 12462 | LSI->GLTemplateParameterList = TPL; |
| 12463 | |
| 12464 | // Transform the type of the original lambda's call operator. |
| 12465 | // The transformation MUST be done in the CurrentInstantiationScope since |
| 12466 | // it introduces a mapping of the original to the newly created |
| 12467 | // transformed parameters. |
| 12468 | TypeSourceInfo *NewCallOpTSI = nullptr; |
| 12469 | { |
| 12470 | TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo(); |
| 12471 | FunctionProtoTypeLoc OldCallOpFPTL = |
| 12472 | OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>(); |
| 12473 | |
| 12474 | TypeLocBuilder NewCallOpTLBuilder; |
| 12475 | SmallVector<QualType, 4> ExceptionStorage; |
| 12476 | TreeTransform *This = this; // Work around gcc.gnu.org/PR56135. |
| 12477 | QualType NewCallOpType = TransformFunctionProtoType( |
| 12478 | NewCallOpTLBuilder, OldCallOpFPTL, nullptr, Qualifiers(), |
| 12479 | [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) { |
| 12480 | return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI, |
| 12481 | ExceptionStorage, Changed); |
| 12482 | }); |
| 12483 | if (NewCallOpType.isNull()) |
| 12484 | return ExprError(); |
| 12485 | NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context, |
| 12486 | NewCallOpType); |
| 12487 | } |
| 12488 | |
| 12489 | // Transform the trailing requires clause |
| 12490 | ExprResult NewTrailingRequiresClause; |
| 12491 | if (Expr *TRC = E->getCallOperator()->getTrailingRequiresClause()) |
| 12492 | // FIXME: Concepts: Substitution into requires clause should only happen |
| 12493 | // when checking satisfaction. |
| 12494 | NewTrailingRequiresClause = getDerived().TransformExpr(TRC); |
| 12495 | |
| 12496 | // Create the local class that will describe the lambda. |
| 12497 | // FIXME: KnownDependent below is wrong when substituting inside a templated |
| 12498 | // context that isn't a DeclContext (such as a variable template). |
| 12499 | CXXRecordDecl *OldClass = E->getLambdaClass(); |
| 12500 | CXXRecordDecl *Class |
| 12501 | = getSema().createLambdaClosureType(E->getIntroducerRange(), |
| 12502 | NewCallOpTSI, |
| 12503 | /*KnownDependent=*/false, |
| 12504 | E->getCaptureDefault()); |
| 12505 | getDerived().transformedLocalDecl(OldClass, {Class}); |
| 12506 | |
| 12507 | Optional<std::tuple<bool, unsigned, unsigned, Decl *>> Mangling; |
| 12508 | if (getDerived().ReplacingOriginal()) |
| 12509 | Mangling = std::make_tuple(OldClass->hasKnownLambdaInternalLinkage(), |
| 12510 | OldClass->getLambdaManglingNumber(), |
| 12511 | OldClass->getDeviceLambdaManglingNumber(), |
| 12512 | OldClass->getLambdaContextDecl()); |
| 12513 | |
| 12514 | // Build the call operator. |
| 12515 | CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition( |
| 12516 | Class, E->getIntroducerRange(), NewCallOpTSI, |
| 12517 | E->getCallOperator()->getEndLoc(), |
| 12518 | NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams(), |
| 12519 | E->getCallOperator()->getConstexprKind(), |
| 12520 | NewTrailingRequiresClause.get()); |
| 12521 | |
| 12522 | LSI->CallOperator = NewCallOperator; |
| 12523 | |
| 12524 | getDerived().transformAttrs(E->getCallOperator(), NewCallOperator); |
| 12525 | getDerived().transformedLocalDecl(E->getCallOperator(), {NewCallOperator}); |
| 12526 | |
| 12527 | // Number the lambda for linkage purposes if necessary. |
| 12528 | getSema().handleLambdaNumbering(Class, NewCallOperator, Mangling); |
| 12529 | |
| 12530 | // Introduce the context of the call operator. |
| 12531 | Sema::ContextRAII SavedContext(getSema(), NewCallOperator, |
| 12532 | /*NewThisContext*/false); |
| 12533 | |
| 12534 | // Enter the scope of the lambda. |
| 12535 | getSema().buildLambdaScope(LSI, NewCallOperator, |
| 12536 | E->getIntroducerRange(), |
| 12537 | E->getCaptureDefault(), |
| 12538 | E->getCaptureDefaultLoc(), |
| 12539 | E->hasExplicitParameters(), |
| 12540 | E->hasExplicitResultType(), |
| 12541 | E->isMutable()); |
| 12542 | |
| 12543 | bool Invalid = false; |
| 12544 | |
| 12545 | // Transform captures. |
| 12546 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 12547 | CEnd = E->capture_end(); |
| 12548 | C != CEnd; ++C) { |
| 12549 | // When we hit the first implicit capture, tell Sema that we've finished |
| 12550 | // the list of explicit captures. |
| 12551 | if (C->isImplicit()) |
| 12552 | break; |
| 12553 | |
| 12554 | // Capturing 'this' is trivial. |
| 12555 | if (C->capturesThis()) { |
| 12556 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), |
| 12557 | /*BuildAndDiagnose*/ true, nullptr, |
| 12558 | C->getCaptureKind() == LCK_StarThis); |
| 12559 | continue; |
| 12560 | } |
| 12561 | // Captured expression will be recaptured during captured variables |
| 12562 | // rebuilding. |
| 12563 | if (C->capturesVLAType()) |
| 12564 | continue; |
| 12565 | |
| 12566 | // Rebuild init-captures, including the implied field declaration. |
| 12567 | if (E->isInitCapture(C)) { |
| 12568 | TransformedInitCapture &NewC = InitCaptures[C - E->capture_begin()]; |
| 12569 | |
| 12570 | VarDecl *OldVD = C->getCapturedVar(); |
| 12571 | llvm::SmallVector<Decl*, 4> NewVDs; |
| 12572 | |
| 12573 | for (InitCaptureInfoTy &Info : NewC.Expansions) { |
| 12574 | ExprResult Init = Info.first; |
| 12575 | QualType InitQualType = Info.second; |
| 12576 | if (Init.isInvalid() || InitQualType.isNull()) { |
| 12577 | Invalid = true; |
| 12578 | break; |
| 12579 | } |
| 12580 | VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl( |
| 12581 | OldVD->getLocation(), InitQualType, NewC.EllipsisLoc, |
| 12582 | OldVD->getIdentifier(), OldVD->getInitStyle(), Init.get()); |
| 12583 | if (!NewVD) { |
| 12584 | Invalid = true; |
| 12585 | break; |
| 12586 | } |
| 12587 | NewVDs.push_back(NewVD); |
| 12588 | getSema().addInitCapture(LSI, NewVD); |
| 12589 | } |
| 12590 | |
| 12591 | if (Invalid) |
| 12592 | break; |
| 12593 | |
| 12594 | getDerived().transformedLocalDecl(OldVD, NewVDs); |
| 12595 | continue; |
| 12596 | } |
| 12597 | |
| 12598 | assert(C->capturesVariable() && "unexpected kind of lambda capture" ); |
| 12599 | |
| 12600 | // Determine the capture kind for Sema. |
| 12601 | Sema::TryCaptureKind Kind |
| 12602 | = C->isImplicit()? Sema::TryCapture_Implicit |
| 12603 | : C->getCaptureKind() == LCK_ByCopy |
| 12604 | ? Sema::TryCapture_ExplicitByVal |
| 12605 | : Sema::TryCapture_ExplicitByRef; |
| 12606 | SourceLocation EllipsisLoc; |
| 12607 | if (C->isPackExpansion()) { |
| 12608 | UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); |
| 12609 | bool ShouldExpand = false; |
| 12610 | bool RetainExpansion = false; |
| 12611 | Optional<unsigned> NumExpansions; |
| 12612 | if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), |
| 12613 | C->getLocation(), |
| 12614 | Unexpanded, |
| 12615 | ShouldExpand, RetainExpansion, |
| 12616 | NumExpansions)) { |
| 12617 | Invalid = true; |
| 12618 | continue; |
| 12619 | } |
| 12620 | |
| 12621 | if (ShouldExpand) { |
| 12622 | // The transform has determined that we should perform an expansion; |
| 12623 | // transform and capture each of the arguments. |
| 12624 | // expansion of the pattern. Do so. |
| 12625 | VarDecl *Pack = C->getCapturedVar(); |
| 12626 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 12627 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 12628 | VarDecl *CapturedVar |
| 12629 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| 12630 | Pack)); |
| 12631 | if (!CapturedVar) { |
| 12632 | Invalid = true; |
| 12633 | continue; |
| 12634 | } |
| 12635 | |
| 12636 | // Capture the transformed variable. |
| 12637 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); |
| 12638 | } |
| 12639 | |
| 12640 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 12641 | |
| 12642 | continue; |
| 12643 | } |
| 12644 | |
| 12645 | EllipsisLoc = C->getEllipsisLoc(); |
| 12646 | } |
| 12647 | |
| 12648 | // Transform the captured variable. |
| 12649 | VarDecl *CapturedVar |
| 12650 | = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), |
| 12651 | C->getCapturedVar())); |
| 12652 | if (!CapturedVar || CapturedVar->isInvalidDecl()) { |
| 12653 | Invalid = true; |
| 12654 | continue; |
| 12655 | } |
| 12656 | |
| 12657 | // Capture the transformed variable. |
| 12658 | getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind, |
| 12659 | EllipsisLoc); |
| 12660 | } |
| 12661 | getSema().finishLambdaExplicitCaptures(LSI); |
| 12662 | |
| 12663 | // FIXME: Sema's lambda-building mechanism expects us to push an expression |
| 12664 | // evaluation context even if we're not transforming the function body. |
| 12665 | getSema().PushExpressionEvaluationContext( |
| 12666 | Sema::ExpressionEvaluationContext::PotentiallyEvaluated); |
| 12667 | |
| 12668 | // Instantiate the body of the lambda expression. |
| 12669 | StmtResult Body = |
| 12670 | Invalid ? StmtError() : getDerived().TransformLambdaBody(E, E->getBody()); |
| 12671 | |
| 12672 | // ActOnLambda* will pop the function scope for us. |
| 12673 | FuncScopeCleanup.disable(); |
| 12674 | |
| 12675 | if (Body.isInvalid()) { |
| 12676 | SavedContext.pop(); |
| 12677 | getSema().ActOnLambdaError(E->getBeginLoc(), /*CurScope=*/nullptr, |
| 12678 | /*IsInstantiation=*/true); |
| 12679 | return ExprError(); |
| 12680 | } |
| 12681 | |
| 12682 | // Copy the LSI before ActOnFinishFunctionBody removes it. |
| 12683 | // FIXME: This is dumb. Store the lambda information somewhere that outlives |
| 12684 | // the call operator. |
| 12685 | auto LSICopy = *LSI; |
| 12686 | getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(), |
| 12687 | /*IsInstantiation*/ true); |
| 12688 | SavedContext.pop(); |
| 12689 | |
| 12690 | return getSema().BuildLambdaExpr(E->getBeginLoc(), Body.get()->getEndLoc(), |
| 12691 | &LSICopy); |
| 12692 | } |
| 12693 | |
| 12694 | template<typename Derived> |
| 12695 | StmtResult |
| 12696 | TreeTransform<Derived>::TransformLambdaBody(LambdaExpr *E, Stmt *S) { |
| 12697 | return TransformStmt(S); |
| 12698 | } |
| 12699 | |
| 12700 | template<typename Derived> |
| 12701 | StmtResult |
| 12702 | TreeTransform<Derived>::SkipLambdaBody(LambdaExpr *E, Stmt *S) { |
| 12703 | // Transform captures. |
| 12704 | for (LambdaExpr::capture_iterator C = E->capture_begin(), |
| 12705 | CEnd = E->capture_end(); |
| 12706 | C != CEnd; ++C) { |
| 12707 | // When we hit the first implicit capture, tell Sema that we've finished |
| 12708 | // the list of explicit captures. |
| 12709 | if (!C->isImplicit()) |
| 12710 | continue; |
| 12711 | |
| 12712 | // Capturing 'this' is trivial. |
| 12713 | if (C->capturesThis()) { |
| 12714 | getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit(), |
| 12715 | /*BuildAndDiagnose*/ true, nullptr, |
| 12716 | C->getCaptureKind() == LCK_StarThis); |
| 12717 | continue; |
| 12718 | } |
| 12719 | // Captured expression will be recaptured during captured variables |
| 12720 | // rebuilding. |
| 12721 | if (C->capturesVLAType()) |
| 12722 | continue; |
| 12723 | |
| 12724 | assert(C->capturesVariable() && "unexpected kind of lambda capture" ); |
| 12725 | assert(!E->isInitCapture(C) && "implicit init-capture?" ); |
| 12726 | |
| 12727 | // Transform the captured variable. |
| 12728 | VarDecl *CapturedVar = cast_or_null<VarDecl>( |
| 12729 | getDerived().TransformDecl(C->getLocation(), C->getCapturedVar())); |
| 12730 | if (!CapturedVar || CapturedVar->isInvalidDecl()) |
| 12731 | return StmtError(); |
| 12732 | |
| 12733 | // Capture the transformed variable. |
| 12734 | getSema().tryCaptureVariable(CapturedVar, C->getLocation()); |
| 12735 | } |
| 12736 | |
| 12737 | return S; |
| 12738 | } |
| 12739 | |
| 12740 | template<typename Derived> |
| 12741 | ExprResult |
| 12742 | TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( |
| 12743 | CXXUnresolvedConstructExpr *E) { |
| 12744 | TypeSourceInfo *T = |
| 12745 | getDerived().TransformTypeWithDeducedTST(E->getTypeSourceInfo()); |
| 12746 | if (!T) |
| 12747 | return ExprError(); |
| 12748 | |
| 12749 | bool ArgumentChanged = false; |
| 12750 | SmallVector<Expr*, 8> Args; |
| 12751 | Args.reserve(E->getNumArgs()); |
| 12752 | { |
| 12753 | EnterExpressionEvaluationContext Context( |
| 12754 | getSema(), EnterExpressionEvaluationContext::InitList, |
| 12755 | E->isListInitialization()); |
| 12756 | if (getDerived().TransformExprs(E->arg_begin(), E->getNumArgs(), true, Args, |
| 12757 | &ArgumentChanged)) |
| 12758 | return ExprError(); |
| 12759 | } |
| 12760 | |
| 12761 | if (!getDerived().AlwaysRebuild() && |
| 12762 | T == E->getTypeSourceInfo() && |
| 12763 | !ArgumentChanged) |
| 12764 | return E; |
| 12765 | |
| 12766 | // FIXME: we're faking the locations of the commas |
| 12767 | return getDerived().RebuildCXXUnresolvedConstructExpr( |
| 12768 | T, E->getLParenLoc(), Args, E->getRParenLoc(), E->isListInitialization()); |
| 12769 | } |
| 12770 | |
| 12771 | template<typename Derived> |
| 12772 | ExprResult |
| 12773 | TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( |
| 12774 | CXXDependentScopeMemberExpr *E) { |
| 12775 | // Transform the base of the expression. |
| 12776 | ExprResult Base((Expr*) nullptr); |
| 12777 | Expr *OldBase; |
| 12778 | QualType BaseType; |
| 12779 | QualType ObjectType; |
| 12780 | if (!E->isImplicitAccess()) { |
| 12781 | OldBase = E->getBase(); |
| 12782 | Base = getDerived().TransformExpr(OldBase); |
| 12783 | if (Base.isInvalid()) |
| 12784 | return ExprError(); |
| 12785 | |
| 12786 | // Start the member reference and compute the object's type. |
| 12787 | ParsedType ObjectTy; |
| 12788 | bool MayBePseudoDestructor = false; |
| 12789 | Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(), |
| 12790 | E->getOperatorLoc(), |
| 12791 | E->isArrow()? tok::arrow : tok::period, |
| 12792 | ObjectTy, |
| 12793 | MayBePseudoDestructor); |
| 12794 | if (Base.isInvalid()) |
| 12795 | return ExprError(); |
| 12796 | |
| 12797 | ObjectType = ObjectTy.get(); |
| 12798 | BaseType = ((Expr*) Base.get())->getType(); |
| 12799 | } else { |
| 12800 | OldBase = nullptr; |
| 12801 | BaseType = getDerived().TransformType(E->getBaseType()); |
| 12802 | ObjectType = BaseType->castAs<PointerType>()->getPointeeType(); |
| 12803 | } |
| 12804 | |
| 12805 | // Transform the first part of the nested-name-specifier that qualifies |
| 12806 | // the member name. |
| 12807 | NamedDecl *FirstQualifierInScope |
| 12808 | = getDerived().TransformFirstQualifierInScope( |
| 12809 | E->getFirstQualifierFoundInScope(), |
| 12810 | E->getQualifierLoc().getBeginLoc()); |
| 12811 | |
| 12812 | NestedNameSpecifierLoc QualifierLoc; |
| 12813 | if (E->getQualifier()) { |
| 12814 | QualifierLoc |
| 12815 | = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), |
| 12816 | ObjectType, |
| 12817 | FirstQualifierInScope); |
| 12818 | if (!QualifierLoc) |
| 12819 | return ExprError(); |
| 12820 | } |
| 12821 | |
| 12822 | SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); |
| 12823 | |
| 12824 | // TODO: If this is a conversion-function-id, verify that the |
| 12825 | // destination type name (if present) resolves the same way after |
| 12826 | // instantiation as it did in the local scope. |
| 12827 | |
| 12828 | DeclarationNameInfo NameInfo |
| 12829 | = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); |
| 12830 | if (!NameInfo.getName()) |
| 12831 | return ExprError(); |
| 12832 | |
| 12833 | if (!E->hasExplicitTemplateArgs()) { |
| 12834 | // This is a reference to a member without an explicitly-specified |
| 12835 | // template argument list. Optimize for this common case. |
| 12836 | if (!getDerived().AlwaysRebuild() && |
| 12837 | Base.get() == OldBase && |
| 12838 | BaseType == E->getBaseType() && |
| 12839 | QualifierLoc == E->getQualifierLoc() && |
| 12840 | NameInfo.getName() == E->getMember() && |
| 12841 | FirstQualifierInScope == E->getFirstQualifierFoundInScope()) |
| 12842 | return E; |
| 12843 | |
| 12844 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
| 12845 | BaseType, |
| 12846 | E->isArrow(), |
| 12847 | E->getOperatorLoc(), |
| 12848 | QualifierLoc, |
| 12849 | TemplateKWLoc, |
| 12850 | FirstQualifierInScope, |
| 12851 | NameInfo, |
| 12852 | /*TemplateArgs*/nullptr); |
| 12853 | } |
| 12854 | |
| 12855 | TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); |
| 12856 | if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), |
| 12857 | E->getNumTemplateArgs(), |
| 12858 | TransArgs)) |
| 12859 | return ExprError(); |
| 12860 | |
| 12861 | return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), |
| 12862 | BaseType, |
| 12863 | E->isArrow(), |
| 12864 | E->getOperatorLoc(), |
| 12865 | QualifierLoc, |
| 12866 | TemplateKWLoc, |
| 12867 | FirstQualifierInScope, |
| 12868 | NameInfo, |
| 12869 | &TransArgs); |
| 12870 | } |
| 12871 | |
| 12872 | template<typename Derived> |
| 12873 | ExprResult |
| 12874 | TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { |
| 12875 | // Transform the base of the expression. |
| 12876 | ExprResult Base((Expr*) nullptr); |
| 12877 | QualType BaseType; |
| 12878 | if (!Old->isImplicitAccess()) { |
| 12879 | Base = getDerived().TransformExpr(Old->getBase()); |
| 12880 | if (Base.isInvalid()) |
| 12881 | return ExprError(); |
| 12882 | Base = getSema().PerformMemberExprBaseConversion(Base.get(), |
| 12883 | Old->isArrow()); |
| 12884 | if (Base.isInvalid()) |
| 12885 | return ExprError(); |
| 12886 | BaseType = Base.get()->getType(); |
| 12887 | } else { |
| 12888 | BaseType = getDerived().TransformType(Old->getBaseType()); |
| 12889 | } |
| 12890 | |
| 12891 | NestedNameSpecifierLoc QualifierLoc; |
| 12892 | if (Old->getQualifierLoc()) { |
| 12893 | QualifierLoc |
| 12894 | = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); |
| 12895 | if (!QualifierLoc) |
| 12896 | return ExprError(); |
| 12897 | } |
| 12898 | |
| 12899 | SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); |
| 12900 | |
| 12901 | LookupResult R(SemaRef, Old->getMemberNameInfo(), |
| 12902 | Sema::LookupOrdinaryName); |
| 12903 | |
| 12904 | // Transform the declaration set. |
| 12905 | if (TransformOverloadExprDecls(Old, /*RequiresADL*/false, R)) |
| 12906 | return ExprError(); |
| 12907 | |
| 12908 | // Determine the naming class. |
| 12909 | if (Old->getNamingClass()) { |
| 12910 | CXXRecordDecl *NamingClass |
| 12911 | = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( |
| 12912 | Old->getMemberLoc(), |
| 12913 | Old->getNamingClass())); |
| 12914 | if (!NamingClass) |
| 12915 | return ExprError(); |
| 12916 | |
| 12917 | R.setNamingClass(NamingClass); |
| 12918 | } |
| 12919 | |
| 12920 | TemplateArgumentListInfo TransArgs; |
| 12921 | if (Old->hasExplicitTemplateArgs()) { |
| 12922 | TransArgs.setLAngleLoc(Old->getLAngleLoc()); |
| 12923 | TransArgs.setRAngleLoc(Old->getRAngleLoc()); |
| 12924 | if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), |
| 12925 | Old->getNumTemplateArgs(), |
| 12926 | TransArgs)) |
| 12927 | return ExprError(); |
| 12928 | } |
| 12929 | |
| 12930 | // FIXME: to do this check properly, we will need to preserve the |
| 12931 | // first-qualifier-in-scope here, just in case we had a dependent |
| 12932 | // base (and therefore couldn't do the check) and a |
| 12933 | // nested-name-qualifier (and therefore could do the lookup). |
| 12934 | NamedDecl *FirstQualifierInScope = nullptr; |
| 12935 | |
| 12936 | return getDerived().RebuildUnresolvedMemberExpr(Base.get(), |
| 12937 | BaseType, |
| 12938 | Old->getOperatorLoc(), |
| 12939 | Old->isArrow(), |
| 12940 | QualifierLoc, |
| 12941 | TemplateKWLoc, |
| 12942 | FirstQualifierInScope, |
| 12943 | R, |
| 12944 | (Old->hasExplicitTemplateArgs() |
| 12945 | ? &TransArgs : nullptr)); |
| 12946 | } |
| 12947 | |
| 12948 | template<typename Derived> |
| 12949 | ExprResult |
| 12950 | TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { |
| 12951 | EnterExpressionEvaluationContext Unevaluated( |
| 12952 | SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); |
| 12953 | ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); |
| 12954 | if (SubExpr.isInvalid()) |
| 12955 | return ExprError(); |
| 12956 | |
| 12957 | if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) |
| 12958 | return E; |
| 12959 | |
| 12960 | return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); |
| 12961 | } |
| 12962 | |
| 12963 | template<typename Derived> |
| 12964 | ExprResult |
| 12965 | TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { |
| 12966 | ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); |
| 12967 | if (Pattern.isInvalid()) |
| 12968 | return ExprError(); |
| 12969 | |
| 12970 | if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) |
| 12971 | return E; |
| 12972 | |
| 12973 | return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), |
| 12974 | E->getNumExpansions()); |
| 12975 | } |
| 12976 | |
| 12977 | template<typename Derived> |
| 12978 | ExprResult |
| 12979 | TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { |
| 12980 | // If E is not value-dependent, then nothing will change when we transform it. |
| 12981 | // Note: This is an instantiation-centric view. |
| 12982 | if (!E->isValueDependent()) |
| 12983 | return E; |
| 12984 | |
| 12985 | EnterExpressionEvaluationContext Unevaluated( |
| 12986 | getSema(), Sema::ExpressionEvaluationContext::Unevaluated); |
| 12987 | |
| 12988 | ArrayRef<TemplateArgument> PackArgs; |
| 12989 | TemplateArgument ArgStorage; |
| 12990 | |
| 12991 | // Find the argument list to transform. |
| 12992 | if (E->isPartiallySubstituted()) { |
| 12993 | PackArgs = E->getPartialArguments(); |
| 12994 | } else if (E->isValueDependent()) { |
| 12995 | UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); |
| 12996 | bool ShouldExpand = false; |
| 12997 | bool RetainExpansion = false; |
| 12998 | Optional<unsigned> NumExpansions; |
| 12999 | if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), |
| 13000 | Unexpanded, |
| 13001 | ShouldExpand, RetainExpansion, |
| 13002 | NumExpansions)) |
| 13003 | return ExprError(); |
| 13004 | |
| 13005 | // If we need to expand the pack, build a template argument from it and |
| 13006 | // expand that. |
| 13007 | if (ShouldExpand) { |
| 13008 | auto *Pack = E->getPack(); |
| 13009 | if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) { |
| 13010 | ArgStorage = getSema().Context.getPackExpansionType( |
| 13011 | getSema().Context.getTypeDeclType(TTPD), None); |
| 13012 | } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) { |
| 13013 | ArgStorage = TemplateArgument(TemplateName(TTPD), None); |
| 13014 | } else { |
| 13015 | auto *VD = cast<ValueDecl>(Pack); |
| 13016 | ExprResult DRE = getSema().BuildDeclRefExpr( |
| 13017 | VD, VD->getType().getNonLValueExprType(getSema().Context), |
| 13018 | VD->getType()->isReferenceType() ? VK_LValue : VK_RValue, |
| 13019 | E->getPackLoc()); |
| 13020 | if (DRE.isInvalid()) |
| 13021 | return ExprError(); |
| 13022 | ArgStorage = new (getSema().Context) PackExpansionExpr( |
| 13023 | getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None); |
| 13024 | } |
| 13025 | PackArgs = ArgStorage; |
| 13026 | } |
| 13027 | } |
| 13028 | |
| 13029 | // If we're not expanding the pack, just transform the decl. |
| 13030 | if (!PackArgs.size()) { |
| 13031 | auto *Pack = cast_or_null<NamedDecl>( |
| 13032 | getDerived().TransformDecl(E->getPackLoc(), E->getPack())); |
| 13033 | if (!Pack) |
| 13034 | return ExprError(); |
| 13035 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, |
| 13036 | E->getPackLoc(), |
| 13037 | E->getRParenLoc(), None, None); |
| 13038 | } |
| 13039 | |
| 13040 | // Try to compute the result without performing a partial substitution. |
| 13041 | Optional<unsigned> Result = 0; |
| 13042 | for (const TemplateArgument &Arg : PackArgs) { |
| 13043 | if (!Arg.isPackExpansion()) { |
| 13044 | Result = *Result + 1; |
| 13045 | continue; |
| 13046 | } |
| 13047 | |
| 13048 | TemplateArgumentLoc ArgLoc; |
| 13049 | InventTemplateArgumentLoc(Arg, ArgLoc); |
| 13050 | |
| 13051 | // Find the pattern of the pack expansion. |
| 13052 | SourceLocation Ellipsis; |
| 13053 | Optional<unsigned> OrigNumExpansions; |
| 13054 | TemplateArgumentLoc Pattern = |
| 13055 | getSema().getTemplateArgumentPackExpansionPattern(ArgLoc, Ellipsis, |
| 13056 | OrigNumExpansions); |
| 13057 | |
| 13058 | // Substitute under the pack expansion. Do not expand the pack (yet). |
| 13059 | TemplateArgumentLoc OutPattern; |
| 13060 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 13061 | if (getDerived().TransformTemplateArgument(Pattern, OutPattern, |
| 13062 | /*Uneval*/ true)) |
| 13063 | return true; |
| 13064 | |
| 13065 | // See if we can determine the number of arguments from the result. |
| 13066 | Optional<unsigned> NumExpansions = |
| 13067 | getSema().getFullyPackExpandedSize(OutPattern.getArgument()); |
| 13068 | if (!NumExpansions) { |
| 13069 | // No: we must be in an alias template expansion, and we're going to need |
| 13070 | // to actually expand the packs. |
| 13071 | Result = None; |
| 13072 | break; |
| 13073 | } |
| 13074 | |
| 13075 | Result = *Result + *NumExpansions; |
| 13076 | } |
| 13077 | |
| 13078 | // Common case: we could determine the number of expansions without |
| 13079 | // substituting. |
| 13080 | if (Result) |
| 13081 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 13082 | E->getPackLoc(), |
| 13083 | E->getRParenLoc(), *Result, None); |
| 13084 | |
| 13085 | TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(), |
| 13086 | E->getPackLoc()); |
| 13087 | { |
| 13088 | TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity()); |
| 13089 | typedef TemplateArgumentLocInventIterator< |
| 13090 | Derived, const TemplateArgument*> PackLocIterator; |
| 13091 | if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()), |
| 13092 | PackLocIterator(*this, PackArgs.end()), |
| 13093 | TransformedPackArgs, /*Uneval*/true)) |
| 13094 | return ExprError(); |
| 13095 | } |
| 13096 | |
| 13097 | // Check whether we managed to fully-expand the pack. |
| 13098 | // FIXME: Is it possible for us to do so and not hit the early exit path? |
| 13099 | SmallVector<TemplateArgument, 8> Args; |
| 13100 | bool PartialSubstitution = false; |
| 13101 | for (auto &Loc : TransformedPackArgs.arguments()) { |
| 13102 | Args.push_back(Loc.getArgument()); |
| 13103 | if (Loc.getArgument().isPackExpansion()) |
| 13104 | PartialSubstitution = true; |
| 13105 | } |
| 13106 | |
| 13107 | if (PartialSubstitution) |
| 13108 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 13109 | E->getPackLoc(), |
| 13110 | E->getRParenLoc(), None, Args); |
| 13111 | |
| 13112 | return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), |
| 13113 | E->getPackLoc(), E->getRParenLoc(), |
| 13114 | Args.size(), None); |
| 13115 | } |
| 13116 | |
| 13117 | template<typename Derived> |
| 13118 | ExprResult |
| 13119 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( |
| 13120 | SubstNonTypeTemplateParmPackExpr *E) { |
| 13121 | // Default behavior is to do nothing with this transformation. |
| 13122 | return E; |
| 13123 | } |
| 13124 | |
| 13125 | template<typename Derived> |
| 13126 | ExprResult |
| 13127 | TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( |
| 13128 | SubstNonTypeTemplateParmExpr *E) { |
| 13129 | // Default behavior is to do nothing with this transformation. |
| 13130 | return E; |
| 13131 | } |
| 13132 | |
| 13133 | template<typename Derived> |
| 13134 | ExprResult |
| 13135 | TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) { |
| 13136 | // Default behavior is to do nothing with this transformation. |
| 13137 | return E; |
| 13138 | } |
| 13139 | |
| 13140 | template<typename Derived> |
| 13141 | ExprResult |
| 13142 | TreeTransform<Derived>::TransformMaterializeTemporaryExpr( |
| 13143 | MaterializeTemporaryExpr *E) { |
| 13144 | return getDerived().TransformExpr(E->getSubExpr()); |
| 13145 | } |
| 13146 | |
| 13147 | template<typename Derived> |
| 13148 | ExprResult |
| 13149 | TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) { |
| 13150 | UnresolvedLookupExpr *Callee = nullptr; |
| 13151 | if (Expr *OldCallee = E->getCallee()) { |
| 13152 | ExprResult CalleeResult = getDerived().TransformExpr(OldCallee); |
| 13153 | if (CalleeResult.isInvalid()) |
| 13154 | return ExprError(); |
| 13155 | Callee = cast<UnresolvedLookupExpr>(CalleeResult.get()); |
| 13156 | } |
| 13157 | |
| 13158 | Expr *Pattern = E->getPattern(); |
| 13159 | |
| 13160 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 13161 | getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); |
| 13162 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?" ); |
| 13163 | |
| 13164 | // Determine whether the set of unexpanded parameter packs can and should |
| 13165 | // be expanded. |
| 13166 | bool Expand = true; |
| 13167 | bool RetainExpansion = false; |
| 13168 | Optional<unsigned> OrigNumExpansions = E->getNumExpansions(), |
| 13169 | NumExpansions = OrigNumExpansions; |
| 13170 | if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(), |
| 13171 | Pattern->getSourceRange(), |
| 13172 | Unexpanded, |
| 13173 | Expand, RetainExpansion, |
| 13174 | NumExpansions)) |
| 13175 | return true; |
| 13176 | |
| 13177 | if (!Expand) { |
| 13178 | // Do not expand any packs here, just transform and rebuild a fold |
| 13179 | // expression. |
| 13180 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 13181 | |
| 13182 | ExprResult LHS = |
| 13183 | E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult(); |
| 13184 | if (LHS.isInvalid()) |
| 13185 | return true; |
| 13186 | |
| 13187 | ExprResult RHS = |
| 13188 | E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult(); |
| 13189 | if (RHS.isInvalid()) |
| 13190 | return true; |
| 13191 | |
| 13192 | if (!getDerived().AlwaysRebuild() && |
| 13193 | LHS.get() == E->getLHS() && RHS.get() == E->getRHS()) |
| 13194 | return E; |
| 13195 | |
| 13196 | return getDerived().RebuildCXXFoldExpr( |
| 13197 | Callee, E->getBeginLoc(), LHS.get(), E->getOperator(), |
| 13198 | E->getEllipsisLoc(), RHS.get(), E->getEndLoc(), NumExpansions); |
| 13199 | } |
| 13200 | |
| 13201 | // Formally a fold expression expands to nested parenthesized expressions. |
| 13202 | // Enforce this limit to avoid creating trees so deep we can't safely traverse |
| 13203 | // them. |
| 13204 | if (NumExpansions && SemaRef.getLangOpts().BracketDepth < NumExpansions) { |
| 13205 | SemaRef.Diag(E->getEllipsisLoc(), |
| 13206 | clang::diag::err_fold_expression_limit_exceeded) |
| 13207 | << *NumExpansions << SemaRef.getLangOpts().BracketDepth |
| 13208 | << E->getSourceRange(); |
| 13209 | SemaRef.Diag(E->getEllipsisLoc(), diag::note_bracket_depth); |
| 13210 | return ExprError(); |
| 13211 | } |
| 13212 | |
| 13213 | // The transform has determined that we should perform an elementwise |
| 13214 | // expansion of the pattern. Do so. |
| 13215 | ExprResult Result = getDerived().TransformExpr(E->getInit()); |
| 13216 | if (Result.isInvalid()) |
| 13217 | return true; |
| 13218 | bool LeftFold = E->isLeftFold(); |
| 13219 | |
| 13220 | // If we're retaining an expansion for a right fold, it is the innermost |
| 13221 | // component and takes the init (if any). |
| 13222 | if (!LeftFold && RetainExpansion) { |
| 13223 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 13224 | |
| 13225 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 13226 | if (Out.isInvalid()) |
| 13227 | return true; |
| 13228 | |
| 13229 | Result = getDerived().RebuildCXXFoldExpr( |
| 13230 | Callee, E->getBeginLoc(), Out.get(), E->getOperator(), |
| 13231 | E->getEllipsisLoc(), Result.get(), E->getEndLoc(), OrigNumExpansions); |
| 13232 | if (Result.isInvalid()) |
| 13233 | return true; |
| 13234 | } |
| 13235 | |
| 13236 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 13237 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex( |
| 13238 | getSema(), LeftFold ? I : *NumExpansions - I - 1); |
| 13239 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 13240 | if (Out.isInvalid()) |
| 13241 | return true; |
| 13242 | |
| 13243 | if (Out.get()->containsUnexpandedParameterPack()) { |
| 13244 | // We still have a pack; retain a pack expansion for this slice. |
| 13245 | Result = getDerived().RebuildCXXFoldExpr( |
| 13246 | Callee, E->getBeginLoc(), LeftFold ? Result.get() : Out.get(), |
| 13247 | E->getOperator(), E->getEllipsisLoc(), |
| 13248 | LeftFold ? Out.get() : Result.get(), E->getEndLoc(), |
| 13249 | OrigNumExpansions); |
| 13250 | } else if (Result.isUsable()) { |
| 13251 | // We've got down to a single element; build a binary operator. |
| 13252 | Expr *LHS = LeftFold ? Result.get() : Out.get(); |
| 13253 | Expr *RHS = LeftFold ? Out.get() : Result.get(); |
| 13254 | if (Callee) |
| 13255 | Result = getDerived().RebuildCXXOperatorCallExpr( |
| 13256 | BinaryOperator::getOverloadedOperator(E->getOperator()), |
| 13257 | E->getEllipsisLoc(), Callee, LHS, RHS); |
| 13258 | else |
| 13259 | Result = getDerived().RebuildBinaryOperator(E->getEllipsisLoc(), |
| 13260 | E->getOperator(), LHS, RHS); |
| 13261 | } else |
| 13262 | Result = Out; |
| 13263 | |
| 13264 | if (Result.isInvalid()) |
| 13265 | return true; |
| 13266 | } |
| 13267 | |
| 13268 | // If we're retaining an expansion for a left fold, it is the outermost |
| 13269 | // component and takes the complete expansion so far as its init (if any). |
| 13270 | if (LeftFold && RetainExpansion) { |
| 13271 | ForgetPartiallySubstitutedPackRAII Forget(getDerived()); |
| 13272 | |
| 13273 | ExprResult Out = getDerived().TransformExpr(Pattern); |
| 13274 | if (Out.isInvalid()) |
| 13275 | return true; |
| 13276 | |
| 13277 | Result = getDerived().RebuildCXXFoldExpr( |
| 13278 | Callee, E->getBeginLoc(), Result.get(), E->getOperator(), |
| 13279 | E->getEllipsisLoc(), Out.get(), E->getEndLoc(), OrigNumExpansions); |
| 13280 | if (Result.isInvalid()) |
| 13281 | return true; |
| 13282 | } |
| 13283 | |
| 13284 | // If we had no init and an empty pack, and we're not retaining an expansion, |
| 13285 | // then produce a fallback value or error. |
| 13286 | if (Result.isUnset()) |
| 13287 | return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(), |
| 13288 | E->getOperator()); |
| 13289 | |
| 13290 | return Result; |
| 13291 | } |
| 13292 | |
| 13293 | template<typename Derived> |
| 13294 | ExprResult |
| 13295 | TreeTransform<Derived>::TransformCXXStdInitializerListExpr( |
| 13296 | CXXStdInitializerListExpr *E) { |
| 13297 | return getDerived().TransformExpr(E->getSubExpr()); |
| 13298 | } |
| 13299 | |
| 13300 | template<typename Derived> |
| 13301 | ExprResult |
| 13302 | TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { |
| 13303 | return SemaRef.MaybeBindToTemporary(E); |
| 13304 | } |
| 13305 | |
| 13306 | template<typename Derived> |
| 13307 | ExprResult |
| 13308 | TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { |
| 13309 | return E; |
| 13310 | } |
| 13311 | |
| 13312 | template<typename Derived> |
| 13313 | ExprResult |
| 13314 | TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { |
| 13315 | ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); |
| 13316 | if (SubExpr.isInvalid()) |
| 13317 | return ExprError(); |
| 13318 | |
| 13319 | if (!getDerived().AlwaysRebuild() && |
| 13320 | SubExpr.get() == E->getSubExpr()) |
| 13321 | return E; |
| 13322 | |
| 13323 | return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); |
| 13324 | } |
| 13325 | |
| 13326 | template<typename Derived> |
| 13327 | ExprResult |
| 13328 | TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { |
| 13329 | // Transform each of the elements. |
| 13330 | SmallVector<Expr *, 8> Elements; |
| 13331 | bool ArgChanged = false; |
| 13332 | if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), |
| 13333 | /*IsCall=*/false, Elements, &ArgChanged)) |
| 13334 | return ExprError(); |
| 13335 | |
| 13336 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 13337 | return SemaRef.MaybeBindToTemporary(E); |
| 13338 | |
| 13339 | return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), |
| 13340 | Elements.data(), |
| 13341 | Elements.size()); |
| 13342 | } |
| 13343 | |
| 13344 | template<typename Derived> |
| 13345 | ExprResult |
| 13346 | TreeTransform<Derived>::TransformObjCDictionaryLiteral( |
| 13347 | ObjCDictionaryLiteral *E) { |
| 13348 | // Transform each of the elements. |
| 13349 | SmallVector<ObjCDictionaryElement, 8> Elements; |
| 13350 | bool ArgChanged = false; |
| 13351 | for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { |
| 13352 | ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); |
| 13353 | |
| 13354 | if (OrigElement.isPackExpansion()) { |
| 13355 | // This key/value element is a pack expansion. |
| 13356 | SmallVector<UnexpandedParameterPack, 2> Unexpanded; |
| 13357 | getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); |
| 13358 | getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); |
| 13359 | assert(!Unexpanded.empty() && "Pack expansion without parameter packs?" ); |
| 13360 | |
| 13361 | // Determine whether the set of unexpanded parameter packs can |
| 13362 | // and should be expanded. |
| 13363 | bool Expand = true; |
| 13364 | bool RetainExpansion = false; |
| 13365 | Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; |
| 13366 | Optional<unsigned> NumExpansions = OrigNumExpansions; |
| 13367 | SourceRange PatternRange(OrigElement.Key->getBeginLoc(), |
| 13368 | OrigElement.Value->getEndLoc()); |
| 13369 | if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, |
| 13370 | PatternRange, Unexpanded, Expand, |
| 13371 | RetainExpansion, NumExpansions)) |
| 13372 | return ExprError(); |
| 13373 | |
| 13374 | if (!Expand) { |
| 13375 | // The transform has determined that we should perform a simple |
| 13376 | // transformation on the pack expansion, producing another pack |
| 13377 | // expansion. |
| 13378 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); |
| 13379 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 13380 | if (Key.isInvalid()) |
| 13381 | return ExprError(); |
| 13382 | |
| 13383 | if (Key.get() != OrigElement.Key) |
| 13384 | ArgChanged = true; |
| 13385 | |
| 13386 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 13387 | if (Value.isInvalid()) |
| 13388 | return ExprError(); |
| 13389 | |
| 13390 | if (Value.get() != OrigElement.Value) |
| 13391 | ArgChanged = true; |
| 13392 | |
| 13393 | ObjCDictionaryElement Expansion = { |
| 13394 | Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions |
| 13395 | }; |
| 13396 | Elements.push_back(Expansion); |
| 13397 | continue; |
| 13398 | } |
| 13399 | |
| 13400 | // Record right away that the argument was changed. This needs |
| 13401 | // to happen even if the array expands to nothing. |
| 13402 | ArgChanged = true; |
| 13403 | |
| 13404 | // The transform has determined that we should perform an elementwise |
| 13405 | // expansion of the pattern. Do so. |
| 13406 | for (unsigned I = 0; I != *NumExpansions; ++I) { |
| 13407 | Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); |
| 13408 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 13409 | if (Key.isInvalid()) |
| 13410 | return ExprError(); |
| 13411 | |
| 13412 | ExprResult Value = getDerived().TransformExpr(OrigElement.Value); |
| 13413 | if (Value.isInvalid()) |
| 13414 | return ExprError(); |
| 13415 | |
| 13416 | ObjCDictionaryElement Element = { |
| 13417 | Key.get(), Value.get(), SourceLocation(), NumExpansions |
| 13418 | }; |
| 13419 | |
| 13420 | // If any unexpanded parameter packs remain, we still have a |
| 13421 | // pack expansion. |
| 13422 | // FIXME: Can this really happen? |
| 13423 | if (Key.get()->containsUnexpandedParameterPack() || |
| 13424 | Value.get()->containsUnexpandedParameterPack()) |
| 13425 | Element.EllipsisLoc = OrigElement.EllipsisLoc; |
| 13426 | |
| 13427 | Elements.push_back(Element); |
| 13428 | } |
| 13429 | |
| 13430 | // FIXME: Retain a pack expansion if RetainExpansion is true. |
| 13431 | |
| 13432 | // We've finished with this pack expansion. |
| 13433 | continue; |
| 13434 | } |
| 13435 | |
| 13436 | // Transform and check key. |
| 13437 | ExprResult Key = getDerived().TransformExpr(OrigElement.Key); |
| 13438 | if (Key.isInvalid()) |
| 13439 | return ExprError(); |
| 13440 | |
| 13441 | if (Key.get() != OrigElement.Key) |
| 13442 | ArgChanged = true; |
| 13443 | |
| 13444 | // Transform and check value. |
| 13445 | ExprResult Value |
| 13446 | = getDerived().TransformExpr(OrigElement.Value); |
| 13447 | if (Value.isInvalid()) |
| 13448 | return ExprError(); |
| 13449 | |
| 13450 | if (Value.get() != OrigElement.Value) |
| 13451 | ArgChanged = true; |
| 13452 | |
| 13453 | ObjCDictionaryElement Element = { |
| 13454 | Key.get(), Value.get(), SourceLocation(), None |
| 13455 | }; |
| 13456 | Elements.push_back(Element); |
| 13457 | } |
| 13458 | |
| 13459 | if (!getDerived().AlwaysRebuild() && !ArgChanged) |
| 13460 | return SemaRef.MaybeBindToTemporary(E); |
| 13461 | |
| 13462 | return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), |
| 13463 | Elements); |
| 13464 | } |
| 13465 | |
| 13466 | template<typename Derived> |
| 13467 | ExprResult |
| 13468 | TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { |
| 13469 | TypeSourceInfo *EncodedTypeInfo |
| 13470 | = getDerived().TransformType(E->getEncodedTypeSourceInfo()); |
| 13471 | if (!EncodedTypeInfo) |
| 13472 | return ExprError(); |
| 13473 | |
| 13474 | if (!getDerived().AlwaysRebuild() && |
| 13475 | EncodedTypeInfo == E->getEncodedTypeSourceInfo()) |
| 13476 | return E; |
| 13477 | |
| 13478 | return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), |
| 13479 | EncodedTypeInfo, |
| 13480 | E->getRParenLoc()); |
| 13481 | } |
| 13482 | |
| 13483 | template<typename Derived> |
| 13484 | ExprResult TreeTransform<Derived>:: |
| 13485 | TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { |
| 13486 | // This is a kind of implicit conversion, and it needs to get dropped |
| 13487 | // and recomputed for the same general reasons that ImplicitCastExprs |
| 13488 | // do, as well a more specific one: this expression is only valid when |
| 13489 | // it appears *immediately* as an argument expression. |
| 13490 | return getDerived().TransformExpr(E->getSubExpr()); |
| 13491 | } |
| 13492 | |
| 13493 | template<typename Derived> |
| 13494 | ExprResult TreeTransform<Derived>:: |
| 13495 | TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { |
| 13496 | TypeSourceInfo *TSInfo |
| 13497 | = getDerived().TransformType(E->getTypeInfoAsWritten()); |
| 13498 | if (!TSInfo) |
| 13499 | return ExprError(); |
| 13500 | |
| 13501 | ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); |
| 13502 | if (Result.isInvalid()) |
| 13503 | return ExprError(); |
| 13504 | |
| 13505 | if (!getDerived().AlwaysRebuild() && |
| 13506 | TSInfo == E->getTypeInfoAsWritten() && |
| 13507 | Result.get() == E->getSubExpr()) |
| 13508 | return E; |
| 13509 | |
| 13510 | return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), |
| 13511 | E->getBridgeKeywordLoc(), TSInfo, |
| 13512 | Result.get()); |
| 13513 | } |
| 13514 | |
| 13515 | template <typename Derived> |
| 13516 | ExprResult TreeTransform<Derived>::TransformObjCAvailabilityCheckExpr( |
| 13517 | ObjCAvailabilityCheckExpr *E) { |
| 13518 | return E; |
| 13519 | } |
| 13520 | |
| 13521 | template<typename Derived> |
| 13522 | ExprResult |
| 13523 | TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { |
| 13524 | // Transform arguments. |
| 13525 | bool ArgChanged = false; |
| 13526 | SmallVector<Expr*, 8> Args; |
| 13527 | Args.reserve(E->getNumArgs()); |
| 13528 | if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, |
| 13529 | &ArgChanged)) |
| 13530 | return ExprError(); |
| 13531 | |
| 13532 | if (E->getReceiverKind() == ObjCMessageExpr::Class) { |
| 13533 | // Class message: transform the receiver type. |
| 13534 | TypeSourceInfo *ReceiverTypeInfo |
| 13535 | = getDerived().TransformType(E->getClassReceiverTypeInfo()); |
| 13536 | if (!ReceiverTypeInfo) |
| 13537 | return ExprError(); |
| 13538 | |
| 13539 | // If nothing changed, just retain the existing message send. |
| 13540 | if (!getDerived().AlwaysRebuild() && |
| 13541 | ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) |
| 13542 | return SemaRef.MaybeBindToTemporary(E); |
| 13543 | |
| 13544 | // Build a new class message send. |
| 13545 | SmallVector<SourceLocation, 16> SelLocs; |
| 13546 | E->getSelectorLocs(SelLocs); |
| 13547 | return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, |
| 13548 | E->getSelector(), |
| 13549 | SelLocs, |
| 13550 | E->getMethodDecl(), |
| 13551 | E->getLeftLoc(), |
| 13552 | Args, |
| 13553 | E->getRightLoc()); |
| 13554 | } |
| 13555 | else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass || |
| 13556 | E->getReceiverKind() == ObjCMessageExpr::SuperInstance) { |
| 13557 | if (!E->getMethodDecl()) |
| 13558 | return ExprError(); |
| 13559 | |
| 13560 | // Build a new class message send to 'super'. |
| 13561 | SmallVector<SourceLocation, 16> SelLocs; |
| 13562 | E->getSelectorLocs(SelLocs); |
| 13563 | return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(), |
| 13564 | E->getSelector(), |
| 13565 | SelLocs, |
| 13566 | E->getReceiverType(), |
| 13567 | E->getMethodDecl(), |
| 13568 | E->getLeftLoc(), |
| 13569 | Args, |
| 13570 | E->getRightLoc()); |
| 13571 | } |
| 13572 | |
| 13573 | // Instance message: transform the receiver |
| 13574 | assert(E->getReceiverKind() == ObjCMessageExpr::Instance && |
| 13575 | "Only class and instance messages may be instantiated" ); |
| 13576 | ExprResult Receiver |
| 13577 | = getDerived().TransformExpr(E->getInstanceReceiver()); |
| 13578 | if (Receiver.isInvalid()) |
| 13579 | return ExprError(); |
| 13580 | |
| 13581 | // If nothing changed, just retain the existing message send. |
| 13582 | if (!getDerived().AlwaysRebuild() && |
| 13583 | Receiver.get() == E->getInstanceReceiver() && !ArgChanged) |
| 13584 | return SemaRef.MaybeBindToTemporary(E); |
| 13585 | |
| 13586 | // Build a new instance message send. |
| 13587 | SmallVector<SourceLocation, 16> SelLocs; |
| 13588 | E->getSelectorLocs(SelLocs); |
| 13589 | return getDerived().RebuildObjCMessageExpr(Receiver.get(), |
| 13590 | E->getSelector(), |
| 13591 | SelLocs, |
| 13592 | E->getMethodDecl(), |
| 13593 | E->getLeftLoc(), |
| 13594 | Args, |
| 13595 | E->getRightLoc()); |
| 13596 | } |
| 13597 | |
| 13598 | template<typename Derived> |
| 13599 | ExprResult |
| 13600 | TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { |
| 13601 | return E; |
| 13602 | } |
| 13603 | |
| 13604 | template<typename Derived> |
| 13605 | ExprResult |
| 13606 | TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { |
| 13607 | return E; |
| 13608 | } |
| 13609 | |
| 13610 | template<typename Derived> |
| 13611 | ExprResult |
| 13612 | TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
| 13613 | // Transform the base expression. |
| 13614 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 13615 | if (Base.isInvalid()) |
| 13616 | return ExprError(); |
| 13617 | |
| 13618 | // We don't need to transform the ivar; it will never change. |
| 13619 | |
| 13620 | // If nothing changed, just retain the existing expression. |
| 13621 | if (!getDerived().AlwaysRebuild() && |
| 13622 | Base.get() == E->getBase()) |
| 13623 | return E; |
| 13624 | |
| 13625 | return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), |
| 13626 | E->getLocation(), |
| 13627 | E->isArrow(), E->isFreeIvar()); |
| 13628 | } |
| 13629 | |
| 13630 | template<typename Derived> |
| 13631 | ExprResult |
| 13632 | TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 13633 | // 'super' and types never change. Property never changes. Just |
| 13634 | // retain the existing expression. |
| 13635 | if (!E->isObjectReceiver()) |
| 13636 | return E; |
| 13637 | |
| 13638 | // Transform the base expression. |
| 13639 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 13640 | if (Base.isInvalid()) |
| 13641 | return ExprError(); |
| 13642 | |
| 13643 | // We don't need to transform the property; it will never change. |
| 13644 | |
| 13645 | // If nothing changed, just retain the existing expression. |
| 13646 | if (!getDerived().AlwaysRebuild() && |
| 13647 | Base.get() == E->getBase()) |
| 13648 | return E; |
| 13649 | |
| 13650 | if (E->isExplicitProperty()) |
| 13651 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 13652 | E->getExplicitProperty(), |
| 13653 | E->getLocation()); |
| 13654 | |
| 13655 | return getDerived().RebuildObjCPropertyRefExpr(Base.get(), |
| 13656 | SemaRef.Context.PseudoObjectTy, |
| 13657 | E->getImplicitPropertyGetter(), |
| 13658 | E->getImplicitPropertySetter(), |
| 13659 | E->getLocation()); |
| 13660 | } |
| 13661 | |
| 13662 | template<typename Derived> |
| 13663 | ExprResult |
| 13664 | TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { |
| 13665 | // Transform the base expression. |
| 13666 | ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); |
| 13667 | if (Base.isInvalid()) |
| 13668 | return ExprError(); |
| 13669 | |
| 13670 | // Transform the key expression. |
| 13671 | ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); |
| 13672 | if (Key.isInvalid()) |
| 13673 | return ExprError(); |
| 13674 | |
| 13675 | // If nothing changed, just retain the existing expression. |
| 13676 | if (!getDerived().AlwaysRebuild() && |
| 13677 | Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) |
| 13678 | return E; |
| 13679 | |
| 13680 | return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), |
| 13681 | Base.get(), Key.get(), |
| 13682 | E->getAtIndexMethodDecl(), |
| 13683 | E->setAtIndexMethodDecl()); |
| 13684 | } |
| 13685 | |
| 13686 | template<typename Derived> |
| 13687 | ExprResult |
| 13688 | TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { |
| 13689 | // Transform the base expression. |
| 13690 | ExprResult Base = getDerived().TransformExpr(E->getBase()); |
| 13691 | if (Base.isInvalid()) |
| 13692 | return ExprError(); |
| 13693 | |
| 13694 | // If nothing changed, just retain the existing expression. |
| 13695 | if (!getDerived().AlwaysRebuild() && |
| 13696 | Base.get() == E->getBase()) |
| 13697 | return E; |
| 13698 | |
| 13699 | return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), |
| 13700 | E->getOpLoc(), |
| 13701 | E->isArrow()); |
| 13702 | } |
| 13703 | |
| 13704 | template<typename Derived> |
| 13705 | ExprResult |
| 13706 | TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { |
| 13707 | bool ArgumentChanged = false; |
| 13708 | SmallVector<Expr*, 8> SubExprs; |
| 13709 | SubExprs.reserve(E->getNumSubExprs()); |
| 13710 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 13711 | SubExprs, &ArgumentChanged)) |
| 13712 | return ExprError(); |
| 13713 | |
| 13714 | if (!getDerived().AlwaysRebuild() && |
| 13715 | !ArgumentChanged) |
| 13716 | return E; |
| 13717 | |
| 13718 | return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), |
| 13719 | SubExprs, |
| 13720 | E->getRParenLoc()); |
| 13721 | } |
| 13722 | |
| 13723 | template<typename Derived> |
| 13724 | ExprResult |
| 13725 | TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) { |
| 13726 | ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr()); |
| 13727 | if (SrcExpr.isInvalid()) |
| 13728 | return ExprError(); |
| 13729 | |
| 13730 | TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); |
| 13731 | if (!Type) |
| 13732 | return ExprError(); |
| 13733 | |
| 13734 | if (!getDerived().AlwaysRebuild() && |
| 13735 | Type == E->getTypeSourceInfo() && |
| 13736 | SrcExpr.get() == E->getSrcExpr()) |
| 13737 | return E; |
| 13738 | |
| 13739 | return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(), |
| 13740 | SrcExpr.get(), Type, |
| 13741 | E->getRParenLoc()); |
| 13742 | } |
| 13743 | |
| 13744 | template<typename Derived> |
| 13745 | ExprResult |
| 13746 | TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { |
| 13747 | BlockDecl *oldBlock = E->getBlockDecl(); |
| 13748 | |
| 13749 | SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr); |
| 13750 | BlockScopeInfo *blockScope = SemaRef.getCurBlock(); |
| 13751 | |
| 13752 | blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); |
| 13753 | blockScope->TheDecl->setBlockMissingReturnType( |
| 13754 | oldBlock->blockMissingReturnType()); |
| 13755 | |
| 13756 | SmallVector<ParmVarDecl*, 4> params; |
| 13757 | SmallVector<QualType, 4> paramTypes; |
| 13758 | |
| 13759 | const FunctionProtoType *exprFunctionType = E->getFunctionType(); |
| 13760 | |
| 13761 | // Parameter substitution. |
| 13762 | Sema::ExtParameterInfoBuilder extParamInfos; |
| 13763 | if (getDerived().TransformFunctionTypeParams( |
| 13764 | E->getCaretLocation(), oldBlock->parameters(), nullptr, |
| 13765 | exprFunctionType->getExtParameterInfosOrNull(), paramTypes, ¶ms, |
| 13766 | extParamInfos)) { |
| 13767 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
| 13768 | return ExprError(); |
| 13769 | } |
| 13770 | |
| 13771 | QualType exprResultType = |
| 13772 | getDerived().TransformType(exprFunctionType->getReturnType()); |
| 13773 | |
| 13774 | auto epi = exprFunctionType->getExtProtoInfo(); |
| 13775 | epi.ExtParameterInfos = extParamInfos.getPointerOrNull(paramTypes.size()); |
| 13776 | |
| 13777 | QualType functionType = |
| 13778 | getDerived().RebuildFunctionProtoType(exprResultType, paramTypes, epi); |
| 13779 | blockScope->FunctionType = functionType; |
| 13780 | |
| 13781 | // Set the parameters on the block decl. |
| 13782 | if (!params.empty()) |
| 13783 | blockScope->TheDecl->setParams(params); |
| 13784 | |
| 13785 | if (!oldBlock->blockMissingReturnType()) { |
| 13786 | blockScope->HasImplicitReturnType = false; |
| 13787 | blockScope->ReturnType = exprResultType; |
| 13788 | } |
| 13789 | |
| 13790 | // Transform the body |
| 13791 | StmtResult body = getDerived().TransformStmt(E->getBody()); |
| 13792 | if (body.isInvalid()) { |
| 13793 | getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr); |
| 13794 | return ExprError(); |
| 13795 | } |
| 13796 | |
| 13797 | #ifndef NDEBUG |
| 13798 | // In builds with assertions, make sure that we captured everything we |
| 13799 | // captured before. |
| 13800 | if (!SemaRef.getDiagnostics().hasErrorOccurred()) { |
| 13801 | for (const auto &I : oldBlock->captures()) { |
| 13802 | VarDecl *oldCapture = I.getVariable(); |
| 13803 | |
| 13804 | // Ignore parameter packs. |
| 13805 | if (oldCapture->isParameterPack()) |
| 13806 | continue; |
| 13807 | |
| 13808 | VarDecl *newCapture = |
| 13809 | cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), |
| 13810 | oldCapture)); |
| 13811 | assert(blockScope->CaptureMap.count(newCapture)); |
| 13812 | } |
| 13813 | assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); |
| 13814 | } |
| 13815 | #endif |
| 13816 | |
| 13817 | return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), |
| 13818 | /*Scope=*/nullptr); |
| 13819 | } |
| 13820 | |
| 13821 | template<typename Derived> |
| 13822 | ExprResult |
| 13823 | TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { |
| 13824 | llvm_unreachable("Cannot transform asType expressions yet" ); |
| 13825 | } |
| 13826 | |
| 13827 | template<typename Derived> |
| 13828 | ExprResult |
| 13829 | TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { |
| 13830 | bool ArgumentChanged = false; |
| 13831 | SmallVector<Expr*, 8> SubExprs; |
| 13832 | SubExprs.reserve(E->getNumSubExprs()); |
| 13833 | if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, |
| 13834 | SubExprs, &ArgumentChanged)) |
| 13835 | return ExprError(); |
| 13836 | |
| 13837 | if (!getDerived().AlwaysRebuild() && |
| 13838 | !ArgumentChanged) |
| 13839 | return E; |
| 13840 | |
| 13841 | return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, |
| 13842 | E->getOp(), E->getRParenLoc()); |
| 13843 | } |
| 13844 | |
| 13845 | //===----------------------------------------------------------------------===// |
| 13846 | // Type reconstruction |
| 13847 | //===----------------------------------------------------------------------===// |
| 13848 | |
| 13849 | template<typename Derived> |
| 13850 | QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, |
| 13851 | SourceLocation Star) { |
| 13852 | return SemaRef.BuildPointerType(PointeeType, Star, |
| 13853 | getDerived().getBaseEntity()); |
| 13854 | } |
| 13855 | |
| 13856 | template<typename Derived> |
| 13857 | QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, |
| 13858 | SourceLocation Star) { |
| 13859 | return SemaRef.BuildBlockPointerType(PointeeType, Star, |
| 13860 | getDerived().getBaseEntity()); |
| 13861 | } |
| 13862 | |
| 13863 | template<typename Derived> |
| 13864 | QualType |
| 13865 | TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, |
| 13866 | bool WrittenAsLValue, |
| 13867 | SourceLocation Sigil) { |
| 13868 | return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, |
| 13869 | Sigil, getDerived().getBaseEntity()); |
| 13870 | } |
| 13871 | |
| 13872 | template<typename Derived> |
| 13873 | QualType |
| 13874 | TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, |
| 13875 | QualType ClassType, |
| 13876 | SourceLocation Sigil) { |
| 13877 | return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil, |
| 13878 | getDerived().getBaseEntity()); |
| 13879 | } |
| 13880 | |
| 13881 | template<typename Derived> |
| 13882 | QualType TreeTransform<Derived>::RebuildObjCTypeParamType( |
| 13883 | const ObjCTypeParamDecl *Decl, |
| 13884 | SourceLocation ProtocolLAngleLoc, |
| 13885 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 13886 | ArrayRef<SourceLocation> ProtocolLocs, |
| 13887 | SourceLocation ProtocolRAngleLoc) { |
| 13888 | return SemaRef.BuildObjCTypeParamType(Decl, |
| 13889 | ProtocolLAngleLoc, Protocols, |
| 13890 | ProtocolLocs, ProtocolRAngleLoc, |
| 13891 | /*FailOnError=*/true); |
| 13892 | } |
| 13893 | |
| 13894 | template<typename Derived> |
| 13895 | QualType TreeTransform<Derived>::RebuildObjCObjectType( |
| 13896 | QualType BaseType, |
| 13897 | SourceLocation Loc, |
| 13898 | SourceLocation TypeArgsLAngleLoc, |
| 13899 | ArrayRef<TypeSourceInfo *> TypeArgs, |
| 13900 | SourceLocation TypeArgsRAngleLoc, |
| 13901 | SourceLocation ProtocolLAngleLoc, |
| 13902 | ArrayRef<ObjCProtocolDecl *> Protocols, |
| 13903 | ArrayRef<SourceLocation> ProtocolLocs, |
| 13904 | SourceLocation ProtocolRAngleLoc) { |
| 13905 | return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc, |
| 13906 | TypeArgs, TypeArgsRAngleLoc, |
| 13907 | ProtocolLAngleLoc, Protocols, ProtocolLocs, |
| 13908 | ProtocolRAngleLoc, |
| 13909 | /*FailOnError=*/true); |
| 13910 | } |
| 13911 | |
| 13912 | template<typename Derived> |
| 13913 | QualType TreeTransform<Derived>::RebuildObjCObjectPointerType( |
| 13914 | QualType PointeeType, |
| 13915 | SourceLocation Star) { |
| 13916 | return SemaRef.Context.getObjCObjectPointerType(PointeeType); |
| 13917 | } |
| 13918 | |
| 13919 | template<typename Derived> |
| 13920 | QualType |
| 13921 | TreeTransform<Derived>::RebuildArrayType(QualType ElementType, |
| 13922 | ArrayType::ArraySizeModifier SizeMod, |
| 13923 | const llvm::APInt *Size, |
| 13924 | Expr *SizeExpr, |
| 13925 | unsigned IndexTypeQuals, |
| 13926 | SourceRange BracketsRange) { |
| 13927 | if (SizeExpr || !Size) |
| 13928 | return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, |
| 13929 | IndexTypeQuals, BracketsRange, |
| 13930 | getDerived().getBaseEntity()); |
| 13931 | |
| 13932 | QualType Types[] = { |
| 13933 | SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, |
| 13934 | SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, |
| 13935 | SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty |
| 13936 | }; |
| 13937 | const unsigned NumTypes = llvm::array_lengthof(Types); |
| 13938 | QualType SizeType; |
| 13939 | for (unsigned I = 0; I != NumTypes; ++I) |
| 13940 | if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { |
| 13941 | SizeType = Types[I]; |
| 13942 | break; |
| 13943 | } |
| 13944 | |
| 13945 | // Note that we can return a VariableArrayType here in the case where |
| 13946 | // the element type was a dependent VariableArrayType. |
| 13947 | IntegerLiteral *ArraySize |
| 13948 | = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, |
| 13949 | /*FIXME*/BracketsRange.getBegin()); |
| 13950 | return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, |
| 13951 | IndexTypeQuals, BracketsRange, |
| 13952 | getDerived().getBaseEntity()); |
| 13953 | } |
| 13954 | |
| 13955 | template<typename Derived> |
| 13956 | QualType |
| 13957 | TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, |
| 13958 | ArrayType::ArraySizeModifier SizeMod, |
| 13959 | const llvm::APInt &Size, |
| 13960 | Expr *SizeExpr, |
| 13961 | unsigned IndexTypeQuals, |
| 13962 | SourceRange BracketsRange) { |
| 13963 | return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, SizeExpr, |
| 13964 | IndexTypeQuals, BracketsRange); |
| 13965 | } |
| 13966 | |
| 13967 | template<typename Derived> |
| 13968 | QualType |
| 13969 | TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, |
| 13970 | ArrayType::ArraySizeModifier SizeMod, |
| 13971 | unsigned IndexTypeQuals, |
| 13972 | SourceRange BracketsRange) { |
| 13973 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr, |
| 13974 | IndexTypeQuals, BracketsRange); |
| 13975 | } |
| 13976 | |
| 13977 | template<typename Derived> |
| 13978 | QualType |
| 13979 | TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, |
| 13980 | ArrayType::ArraySizeModifier SizeMod, |
| 13981 | Expr *SizeExpr, |
| 13982 | unsigned IndexTypeQuals, |
| 13983 | SourceRange BracketsRange) { |
| 13984 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
| 13985 | SizeExpr, |
| 13986 | IndexTypeQuals, BracketsRange); |
| 13987 | } |
| 13988 | |
| 13989 | template<typename Derived> |
| 13990 | QualType |
| 13991 | TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, |
| 13992 | ArrayType::ArraySizeModifier SizeMod, |
| 13993 | Expr *SizeExpr, |
| 13994 | unsigned IndexTypeQuals, |
| 13995 | SourceRange BracketsRange) { |
| 13996 | return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, |
| 13997 | SizeExpr, |
| 13998 | IndexTypeQuals, BracketsRange); |
| 13999 | } |
| 14000 | |
| 14001 | template <typename Derived> |
| 14002 | QualType TreeTransform<Derived>::RebuildDependentAddressSpaceType( |
| 14003 | QualType PointeeType, Expr *AddrSpaceExpr, SourceLocation AttributeLoc) { |
| 14004 | return SemaRef.BuildAddressSpaceAttr(PointeeType, AddrSpaceExpr, |
| 14005 | AttributeLoc); |
| 14006 | } |
| 14007 | |
| 14008 | template <typename Derived> |
| 14009 | QualType |
| 14010 | TreeTransform<Derived>::RebuildVectorType(QualType ElementType, |
| 14011 | unsigned NumElements, |
| 14012 | VectorType::VectorKind VecKind) { |
| 14013 | // FIXME: semantic checking! |
| 14014 | return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); |
| 14015 | } |
| 14016 | |
| 14017 | template <typename Derived> |
| 14018 | QualType TreeTransform<Derived>::RebuildDependentVectorType( |
| 14019 | QualType ElementType, Expr *SizeExpr, SourceLocation AttributeLoc, |
| 14020 | VectorType::VectorKind VecKind) { |
| 14021 | return SemaRef.BuildVectorType(ElementType, SizeExpr, AttributeLoc); |
| 14022 | } |
| 14023 | |
| 14024 | template<typename Derived> |
| 14025 | QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, |
| 14026 | unsigned NumElements, |
| 14027 | SourceLocation AttributeLoc) { |
| 14028 | llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 14029 | NumElements, true); |
| 14030 | IntegerLiteral *VectorSize |
| 14031 | = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, |
| 14032 | AttributeLoc); |
| 14033 | return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); |
| 14034 | } |
| 14035 | |
| 14036 | template<typename Derived> |
| 14037 | QualType |
| 14038 | TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, |
| 14039 | Expr *SizeExpr, |
| 14040 | SourceLocation AttributeLoc) { |
| 14041 | return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); |
| 14042 | } |
| 14043 | |
| 14044 | template <typename Derived> |
| 14045 | QualType TreeTransform<Derived>::RebuildConstantMatrixType( |
| 14046 | QualType ElementType, unsigned NumRows, unsigned NumColumns) { |
| 14047 | return SemaRef.Context.getConstantMatrixType(ElementType, NumRows, |
| 14048 | NumColumns); |
| 14049 | } |
| 14050 | |
| 14051 | template <typename Derived> |
| 14052 | QualType TreeTransform<Derived>::RebuildDependentSizedMatrixType( |
| 14053 | QualType ElementType, Expr *RowExpr, Expr *ColumnExpr, |
| 14054 | SourceLocation AttributeLoc) { |
| 14055 | return SemaRef.BuildMatrixType(ElementType, RowExpr, ColumnExpr, |
| 14056 | AttributeLoc); |
| 14057 | } |
| 14058 | |
| 14059 | template<typename Derived> |
| 14060 | QualType TreeTransform<Derived>::RebuildFunctionProtoType( |
| 14061 | QualType T, |
| 14062 | MutableArrayRef<QualType> ParamTypes, |
| 14063 | const FunctionProtoType::ExtProtoInfo &EPI) { |
| 14064 | return SemaRef.BuildFunctionType(T, ParamTypes, |
| 14065 | getDerived().getBaseLocation(), |
| 14066 | getDerived().getBaseEntity(), |
| 14067 | EPI); |
| 14068 | } |
| 14069 | |
| 14070 | template<typename Derived> |
| 14071 | QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { |
| 14072 | return SemaRef.Context.getFunctionNoProtoType(T); |
| 14073 | } |
| 14074 | |
| 14075 | template<typename Derived> |
| 14076 | QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(SourceLocation Loc, |
| 14077 | Decl *D) { |
| 14078 | assert(D && "no decl found" ); |
| 14079 | if (D->isInvalidDecl()) return QualType(); |
| 14080 | |
| 14081 | // FIXME: Doesn't account for ObjCInterfaceDecl! |
| 14082 | TypeDecl *Ty; |
| 14083 | if (auto *UPD = dyn_cast<UsingPackDecl>(D)) { |
| 14084 | // A valid resolved using typename pack expansion decl can have multiple |
| 14085 | // UsingDecls, but they must each have exactly one type, and it must be |
| 14086 | // the same type in every case. But we must have at least one expansion! |
| 14087 | if (UPD->expansions().empty()) { |
| 14088 | getSema().Diag(Loc, diag::err_using_pack_expansion_empty) |
| 14089 | << UPD->isCXXClassMember() << UPD; |
| 14090 | return QualType(); |
| 14091 | } |
| 14092 | |
| 14093 | // We might still have some unresolved types. Try to pick a resolved type |
| 14094 | // if we can. The final instantiation will check that the remaining |
| 14095 | // unresolved types instantiate to the type we pick. |
| 14096 | QualType FallbackT; |
| 14097 | QualType T; |
| 14098 | for (auto *E : UPD->expansions()) { |
| 14099 | QualType ThisT = RebuildUnresolvedUsingType(Loc, E); |
| 14100 | if (ThisT.isNull()) |
| 14101 | continue; |
| 14102 | else if (ThisT->getAs<UnresolvedUsingType>()) |
| 14103 | FallbackT = ThisT; |
| 14104 | else if (T.isNull()) |
| 14105 | T = ThisT; |
| 14106 | else |
| 14107 | assert(getSema().Context.hasSameType(ThisT, T) && |
| 14108 | "mismatched resolved types in using pack expansion" ); |
| 14109 | } |
| 14110 | return T.isNull() ? FallbackT : T; |
| 14111 | } else if (auto *Using = dyn_cast<UsingDecl>(D)) { |
| 14112 | assert(Using->hasTypename() && |
| 14113 | "UnresolvedUsingTypenameDecl transformed to non-typename using" ); |
| 14114 | |
| 14115 | // A valid resolved using typename decl points to exactly one type decl. |
| 14116 | assert(++Using->shadow_begin() == Using->shadow_end()); |
| 14117 | Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); |
| 14118 | } else { |
| 14119 | assert(isa<UnresolvedUsingTypenameDecl>(D) && |
| 14120 | "UnresolvedUsingTypenameDecl transformed to non-using decl" ); |
| 14121 | Ty = cast<UnresolvedUsingTypenameDecl>(D); |
| 14122 | } |
| 14123 | |
| 14124 | return SemaRef.Context.getTypeDeclType(Ty); |
| 14125 | } |
| 14126 | |
| 14127 | template<typename Derived> |
| 14128 | QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, |
| 14129 | SourceLocation Loc) { |
| 14130 | return SemaRef.BuildTypeofExprType(E, Loc); |
| 14131 | } |
| 14132 | |
| 14133 | template<typename Derived> |
| 14134 | QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { |
| 14135 | return SemaRef.Context.getTypeOfType(Underlying); |
| 14136 | } |
| 14137 | |
| 14138 | template<typename Derived> |
| 14139 | QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, |
| 14140 | SourceLocation Loc) { |
| 14141 | return SemaRef.BuildDecltypeType(E, Loc); |
| 14142 | } |
| 14143 | |
| 14144 | template<typename Derived> |
| 14145 | QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, |
| 14146 | UnaryTransformType::UTTKind UKind, |
| 14147 | SourceLocation Loc) { |
| 14148 | return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); |
| 14149 | } |
| 14150 | |
| 14151 | template<typename Derived> |
| 14152 | QualType TreeTransform<Derived>::RebuildTemplateSpecializationType( |
| 14153 | TemplateName Template, |
| 14154 | SourceLocation TemplateNameLoc, |
| 14155 | TemplateArgumentListInfo &TemplateArgs) { |
| 14156 | return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); |
| 14157 | } |
| 14158 | |
| 14159 | template<typename Derived> |
| 14160 | QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, |
| 14161 | SourceLocation KWLoc) { |
| 14162 | return SemaRef.BuildAtomicType(ValueType, KWLoc); |
| 14163 | } |
| 14164 | |
| 14165 | template<typename Derived> |
| 14166 | QualType TreeTransform<Derived>::RebuildPipeType(QualType ValueType, |
| 14167 | SourceLocation KWLoc, |
| 14168 | bool isReadPipe) { |
| 14169 | return isReadPipe ? SemaRef.BuildReadPipeType(ValueType, KWLoc) |
| 14170 | : SemaRef.BuildWritePipeType(ValueType, KWLoc); |
| 14171 | } |
| 14172 | |
| 14173 | template <typename Derived> |
| 14174 | QualType TreeTransform<Derived>::RebuildExtIntType(bool IsUnsigned, |
| 14175 | unsigned NumBits, |
| 14176 | SourceLocation Loc) { |
| 14177 | llvm::APInt NumBitsAP(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), |
| 14178 | NumBits, true); |
| 14179 | IntegerLiteral *Bits = IntegerLiteral::Create(SemaRef.Context, NumBitsAP, |
| 14180 | SemaRef.Context.IntTy, Loc); |
| 14181 | return SemaRef.BuildExtIntType(IsUnsigned, Bits, Loc); |
| 14182 | } |
| 14183 | |
| 14184 | template <typename Derived> |
| 14185 | QualType TreeTransform<Derived>::RebuildDependentExtIntType( |
| 14186 | bool IsUnsigned, Expr *NumBitsExpr, SourceLocation Loc) { |
| 14187 | return SemaRef.BuildExtIntType(IsUnsigned, NumBitsExpr, Loc); |
| 14188 | } |
| 14189 | |
| 14190 | template<typename Derived> |
| 14191 | TemplateName |
| 14192 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 14193 | bool TemplateKW, |
| 14194 | TemplateDecl *Template) { |
| 14195 | return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, |
| 14196 | Template); |
| 14197 | } |
| 14198 | |
| 14199 | template<typename Derived> |
| 14200 | TemplateName |
| 14201 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 14202 | SourceLocation TemplateKWLoc, |
| 14203 | const IdentifierInfo &Name, |
| 14204 | SourceLocation NameLoc, |
| 14205 | QualType ObjectType, |
| 14206 | NamedDecl *FirstQualifierInScope, |
| 14207 | bool AllowInjectedClassName) { |
| 14208 | UnqualifiedId TemplateName; |
| 14209 | TemplateName.setIdentifier(&Name, NameLoc); |
| 14210 | Sema::TemplateTy Template; |
| 14211 | getSema().ActOnTemplateName(/*Scope=*/nullptr, SS, TemplateKWLoc, |
| 14212 | TemplateName, ParsedType::make(ObjectType), |
| 14213 | /*EnteringContext=*/false, Template, |
| 14214 | AllowInjectedClassName); |
| 14215 | return Template.get(); |
| 14216 | } |
| 14217 | |
| 14218 | template<typename Derived> |
| 14219 | TemplateName |
| 14220 | TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, |
| 14221 | SourceLocation TemplateKWLoc, |
| 14222 | OverloadedOperatorKind Operator, |
| 14223 | SourceLocation NameLoc, |
| 14224 | QualType ObjectType, |
| 14225 | bool AllowInjectedClassName) { |
| 14226 | UnqualifiedId Name; |
| 14227 | // FIXME: Bogus location information. |
| 14228 | SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; |
| 14229 | Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); |
| 14230 | Sema::TemplateTy Template; |
| 14231 | getSema().ActOnTemplateName( |
| 14232 | /*Scope=*/nullptr, SS, TemplateKWLoc, Name, ParsedType::make(ObjectType), |
| 14233 | /*EnteringContext=*/false, Template, AllowInjectedClassName); |
| 14234 | return Template.get(); |
| 14235 | } |
| 14236 | |
| 14237 | template<typename Derived> |
| 14238 | ExprResult |
| 14239 | TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, |
| 14240 | SourceLocation OpLoc, |
| 14241 | Expr *OrigCallee, |
| 14242 | Expr *First, |
| 14243 | Expr *Second) { |
| 14244 | Expr *Callee = OrigCallee->IgnoreParenCasts(); |
| 14245 | bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); |
| 14246 | |
| 14247 | if (First->getObjectKind() == OK_ObjCProperty) { |
| 14248 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 14249 | if (BinaryOperator::isAssignmentOp(Opc)) |
| 14250 | return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc, |
| 14251 | First, Second); |
| 14252 | ExprResult Result = SemaRef.CheckPlaceholderExpr(First); |
| 14253 | if (Result.isInvalid()) |
| 14254 | return ExprError(); |
| 14255 | First = Result.get(); |
| 14256 | } |
| 14257 | |
| 14258 | if (Second && Second->getObjectKind() == OK_ObjCProperty) { |
| 14259 | ExprResult Result = SemaRef.CheckPlaceholderExpr(Second); |
| 14260 | if (Result.isInvalid()) |
| 14261 | return ExprError(); |
| 14262 | Second = Result.get(); |
| 14263 | } |
| 14264 | |
| 14265 | // Determine whether this should be a builtin operation. |
| 14266 | if (Op == OO_Subscript) { |
| 14267 | if (!First->getType()->isOverloadableType() && |
| 14268 | !Second->getType()->isOverloadableType()) |
| 14269 | return getSema().CreateBuiltinArraySubscriptExpr( |
| 14270 | First, Callee->getBeginLoc(), Second, OpLoc); |
| 14271 | } else if (Op == OO_Arrow) { |
| 14272 | // -> is never a builtin operation. |
| 14273 | return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc); |
| 14274 | } else if (Second == nullptr || isPostIncDec) { |
| 14275 | if (!First->getType()->isOverloadableType() || |
| 14276 | (Op == OO_Amp && getSema().isQualifiedMemberAccess(First))) { |
| 14277 | // The argument is not of overloadable type, or this is an expression |
| 14278 | // of the form &Class::member, so try to create a built-in unary |
| 14279 | // operation. |
| 14280 | UnaryOperatorKind Opc |
| 14281 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 14282 | |
| 14283 | return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); |
| 14284 | } |
| 14285 | } else { |
| 14286 | if (!First->getType()->isOverloadableType() && |
| 14287 | !Second->getType()->isOverloadableType()) { |
| 14288 | // Neither of the arguments is an overloadable type, so try to |
| 14289 | // create a built-in binary operation. |
| 14290 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 14291 | ExprResult Result |
| 14292 | = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); |
| 14293 | if (Result.isInvalid()) |
| 14294 | return ExprError(); |
| 14295 | |
| 14296 | return Result; |
| 14297 | } |
| 14298 | } |
| 14299 | |
| 14300 | // Compute the transformed set of functions (and function templates) to be |
| 14301 | // used during overload resolution. |
| 14302 | UnresolvedSet<16> Functions; |
| 14303 | bool RequiresADL; |
| 14304 | |
| 14305 | if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { |
| 14306 | Functions.append(ULE->decls_begin(), ULE->decls_end()); |
| 14307 | // If the overload could not be resolved in the template definition |
| 14308 | // (because we had a dependent argument), ADL is performed as part of |
| 14309 | // template instantiation. |
| 14310 | RequiresADL = ULE->requiresADL(); |
| 14311 | } else { |
| 14312 | // If we've resolved this to a particular non-member function, just call |
| 14313 | // that function. If we resolved it to a member function, |
| 14314 | // CreateOverloaded* will find that function for us. |
| 14315 | NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl(); |
| 14316 | if (!isa<CXXMethodDecl>(ND)) |
| 14317 | Functions.addDecl(ND); |
| 14318 | RequiresADL = false; |
| 14319 | } |
| 14320 | |
| 14321 | // Add any functions found via argument-dependent lookup. |
| 14322 | Expr *Args[2] = { First, Second }; |
| 14323 | unsigned NumArgs = 1 + (Second != nullptr); |
| 14324 | |
| 14325 | // Create the overloaded operator invocation for unary operators. |
| 14326 | if (NumArgs == 1 || isPostIncDec) { |
| 14327 | UnaryOperatorKind Opc |
| 14328 | = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); |
| 14329 | return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First, |
| 14330 | RequiresADL); |
| 14331 | } |
| 14332 | |
| 14333 | if (Op == OO_Subscript) { |
| 14334 | SourceLocation LBrace; |
| 14335 | SourceLocation RBrace; |
| 14336 | |
| 14337 | if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { |
| 14338 | DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo(); |
| 14339 | LBrace = SourceLocation::getFromRawEncoding( |
| 14340 | NameLoc.CXXOperatorName.BeginOpNameLoc); |
| 14341 | RBrace = SourceLocation::getFromRawEncoding( |
| 14342 | NameLoc.CXXOperatorName.EndOpNameLoc); |
| 14343 | } else { |
| 14344 | LBrace = Callee->getBeginLoc(); |
| 14345 | RBrace = OpLoc; |
| 14346 | } |
| 14347 | |
| 14348 | return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, |
| 14349 | First, Second); |
| 14350 | } |
| 14351 | |
| 14352 | // Create the overloaded operator invocation for binary operators. |
| 14353 | BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); |
| 14354 | ExprResult Result = SemaRef.CreateOverloadedBinOp( |
| 14355 | OpLoc, Opc, Functions, Args[0], Args[1], RequiresADL); |
| 14356 | if (Result.isInvalid()) |
| 14357 | return ExprError(); |
| 14358 | |
| 14359 | return Result; |
| 14360 | } |
| 14361 | |
| 14362 | template<typename Derived> |
| 14363 | ExprResult |
| 14364 | TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, |
| 14365 | SourceLocation OperatorLoc, |
| 14366 | bool isArrow, |
| 14367 | CXXScopeSpec &SS, |
| 14368 | TypeSourceInfo *ScopeType, |
| 14369 | SourceLocation CCLoc, |
| 14370 | SourceLocation TildeLoc, |
| 14371 | PseudoDestructorTypeStorage Destroyed) { |
| 14372 | QualType BaseType = Base->getType(); |
| 14373 | if (Base->isTypeDependent() || Destroyed.getIdentifier() || |
| 14374 | (!isArrow && !BaseType->getAs<RecordType>()) || |
| 14375 | (isArrow && BaseType->getAs<PointerType>() && |
| 14376 | !BaseType->castAs<PointerType>()->getPointeeType() |
| 14377 | ->template getAs<RecordType>())){ |
| 14378 | // This pseudo-destructor expression is still a pseudo-destructor. |
| 14379 | return SemaRef.BuildPseudoDestructorExpr( |
| 14380 | Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType, |
| 14381 | CCLoc, TildeLoc, Destroyed); |
| 14382 | } |
| 14383 | |
| 14384 | TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); |
| 14385 | DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( |
| 14386 | SemaRef.Context.getCanonicalType(DestroyedType->getType()))); |
| 14387 | DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); |
| 14388 | NameInfo.setNamedTypeInfo(DestroyedType); |
| 14389 | |
| 14390 | // The scope type is now known to be a valid nested name specifier |
| 14391 | // component. Tack it on to the end of the nested name specifier. |
| 14392 | if (ScopeType) { |
| 14393 | if (!ScopeType->getType()->getAs<TagType>()) { |
| 14394 | getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(), |
| 14395 | diag::err_expected_class_or_namespace) |
| 14396 | << ScopeType->getType() << getSema().getLangOpts().CPlusPlus; |
| 14397 | return ExprError(); |
| 14398 | } |
| 14399 | SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(), |
| 14400 | CCLoc); |
| 14401 | } |
| 14402 | |
| 14403 | SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. |
| 14404 | return getSema().BuildMemberReferenceExpr(Base, BaseType, |
| 14405 | OperatorLoc, isArrow, |
| 14406 | SS, TemplateKWLoc, |
| 14407 | /*FIXME: FirstQualifier*/ nullptr, |
| 14408 | NameInfo, |
| 14409 | /*TemplateArgs*/ nullptr, |
| 14410 | /*S*/nullptr); |
| 14411 | } |
| 14412 | |
| 14413 | template<typename Derived> |
| 14414 | StmtResult |
| 14415 | TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) { |
| 14416 | SourceLocation Loc = S->getBeginLoc(); |
| 14417 | CapturedDecl *CD = S->getCapturedDecl(); |
| 14418 | unsigned NumParams = CD->getNumParams(); |
| 14419 | unsigned ContextParamPos = CD->getContextParamPosition(); |
| 14420 | SmallVector<Sema::CapturedParamNameType, 4> Params; |
| 14421 | for (unsigned I = 0; I < NumParams; ++I) { |
| 14422 | if (I != ContextParamPos) { |
| 14423 | Params.push_back( |
| 14424 | std::make_pair( |
| 14425 | CD->getParam(I)->getName(), |
| 14426 | getDerived().TransformType(CD->getParam(I)->getType()))); |
| 14427 | } else { |
| 14428 | Params.push_back(std::make_pair(StringRef(), QualType())); |
| 14429 | } |
| 14430 | } |
| 14431 | getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr, |
| 14432 | S->getCapturedRegionKind(), Params); |
| 14433 | StmtResult Body; |
| 14434 | { |
| 14435 | Sema::CompoundScopeRAII CompoundScope(getSema()); |
| 14436 | Body = getDerived().TransformStmt(S->getCapturedStmt()); |
| 14437 | } |
| 14438 | |
| 14439 | if (Body.isInvalid()) { |
| 14440 | getSema().ActOnCapturedRegionError(); |
| 14441 | return StmtError(); |
| 14442 | } |
| 14443 | |
| 14444 | return getSema().ActOnCapturedRegionEnd(Body.get()); |
| 14445 | } |
| 14446 | |
| 14447 | } // end namespace clang |
| 14448 | |
| 14449 | #endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H |
| 14450 | |